OpenPatrician Blog

HELP needed!

Java 9 has landed in OpenPatrician

Every once in a while I get the opportunity from my employer to work on OpenPatrician for one working day and one non working day. So this year the target is to bring OpenPatrician to a modularized Java 9 build and update Maven.

  • Maven compilation based on JDK 1.8.0_131 and maven 3.3.9 works
  • Some Test fail, because this is done in Windows
  • IntelliJ started with Java 9.0.1 compiles OpenPatrician with Project SDK 1.8.0_137
  • IntelliJ with Project SDK 9.0.1 fails to compile: Error:(5, 26) java: package javafx.application does not exist => StackOverflow to the rescue: JavaFx does not exist using Java9 and IntelliJ Idea
    • This did not solve the issue, probably because there were issues with IntelliJ configuration files, especially as the IntelliJ build produced different error messages than the maven build.
    • Created a new project from the existing source and overwrote the *.iml files, then built resulted in the same error messages.
  • Almost every file now has marked import issues in IntelliJ, while they do not bother the compiler (javac). However there were two things that needed to be done to make the first module (OpenPatricianUtilities) compile: add these two modules with argument –add-modules to the javac command.
  • The next module that has serious trouble is the code copied from MarvinFX in MarvinFXEssentials: This test framework makes use of internal API, that is no longer available (i.e. FXRobot). Options are:
    • There is a MarvinFX implementation available, that is compatible with Java 9; so such luck, last commit was 5 years ago
    • Replace with a different FX test framework, that is up for Java 9 (i.e. TestFX): fallback plan, if option 3 fails.
    • Dependencies causing trouble are not required by OpenPatrician testing and can be removed: This seemed to have worked, removing:
      • AwtBasedRobot
      • FxBasedRobot
      • MarvinFxRobotFactory
      • NodeFixture
      • NodeKeyControl
      • NodeMouseControl

causes the module to compile with Java 9 in IntelliJ, if all the tests still work I will see at the end.

  • MinimalMap-Plugin compiles without issues, as does GameEvent, OpenPatricianData (no Java code in there), OpenPatricianModel, OpenPatricianImage, OpenPatricianClientServerInterface, OpenPatricianGameEvent, OpenPatricianJavaFX, OpenPatricianEngine, OpenPatricianServer
  • In OpenPatricianSound replace PlatformImpl with Platform
  • OpenPatricianDisplay had some issues as expected:
    • JavaFX builder no longer exist: replace with controller and setters
    • Move test code infrastructure in javafx.scene.input
  • OpenPatricianTest: Refactor JavaFx builder use
  • Updates in poms to build with Maven (mvn compile):
    • Update source and target in maven-compiler-plugin to 9
    • Update maven-compiler-plugin version to 3.7.0
    • Add compiler args for added modules java.xml.ws.annotation,java.xml.bind
    • Remove dependency to tools.jar in OpenPatricianTest
    • These changes allow mvn compile to complete successfully.
  • Step up and do a mvn clean compile:
    • Some classes that import generated classes fail to compile, as the code structure of the generated classes has changed (some classes became inner classes)
  • Check test with maven:
    • surefire plugin needs argument to add module java.xml.bind (same setup for IntelliJ test run)
    • Some tests fail to compile due to changed imports on generated code (same as above)
    • Tests with wired spring beans require also the module java.se.ee for the Postconstruct annotation
    • Mockito tests using @Mock(answer = Answers.RETURNS_DEEP_STUBS) fail.
  • Final verification of this first step is to create an executable bundle based on Java 9. Did not work as the released javafx-maven-plugin does not support Java 9 yet. There is a snapshot however with which it is possible.
  • Run the application:
    • Add VM options for modules:–add-modules java.xml.bind,java.xml.ws.annotation,java.se.ee
    • Update version check to Java 9
    • On startup there is a warning WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 This is tracked in SPR-15859
    • The executable created for Windows however is not executable.
  • At least for now skip the modularization of OpenPatrician, as lombok is required as a module and that does not yet exist, hopefully with the next release 1.16.22. See Add jdk9 compiler support

Next item on the agenda is Maven update. First bringing all the maven plugins up to the latest versions, managing versions through properties define plugins in pluginManagements and ensure everything is still working. The last point of course proved work intensive, as the new version of jaxb2-maven-plugin does not work with Java 9. Therefore I switched to cxf-xjc-plugin. Also had to drop the cobertura plugin, as this is not yet ready for Java 9.

Next came updating the dependencies. Spring boot was not lifted to version 2.0 due to other dependencies. Same is true for other dependencies with breaking changes.

Last issue on the list was updating the maven version itself to 3.5.2: To fix a circular dependency issue during the bundle packaging, I had to introduce a separate module, which now handles the packaging. This has to be revaluated however, once we have a working javafx-maven-plugin.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.