Jigsaw Maven Integration
Update 24th of March 2017
There seems to be quite a bit of interest on the subject, if you don’t find the answer to what you are looking for don’t hesitate to leave a comment and if I know the answer I’ll update the page so that everybody else can benefit from it.
Update 20th of February 2017
Maven 3.3.9 does not seem to work very well with java 9, Maven 3.2.5 is fine. seems to be some cglib access, there should be a way to open the package if I knew which one was failing.
To run the test with mockito
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin>
all the
-XaddExports:java.base/sun.nio.ch=ALL-UNNAMED
should now be replaced by
--add-opens java.base/sun.nio.ch=ALL-UNNAMED
Update 2nd of November 2016
the Maven plugin 3.6.0 has been officially release with jigsaw support.
Gave it a quick try and I have some issues running/compiling the tests. seems that the test might need a module-info.java.
Will update when I have more info.
Also note that
Maven building java 9-ea with jigsaw
If you don’t have a module-info.java then you don’t need to change anything.
State of maven integration
maven-compiler-plugin
The maven-compiler-plugin on the branch maven-compiler-plugin_jigsaw-ea integrates with javac 9. There is no current release.
checkout
svn co http://svn.apache.org/repos/asf/maven/plugins/branches/maven-compiler-plugin_jigsaw-ea
build
cd maven-compiler-plugin_jigsaw-ea
mvn clean install
you can now use the plugin from your local repo.
I also have a version built available by adding the following to your pom
profile
all you need to do now is to add a profile for jdk 9-ea with that plugin. You will also need to overwrite the asm dependency to 6.0_ALPHA to support the new bytecode version.
module-info.java
The jigsaw maven-compiler-plugin will compile will switch to the modular build if module-info.java is present.
You can find more info at Jigsaw QuickStart. start with a empty one see what you need to import.
et Voila!
Potential troubles
ClassLoaders
The ClassLoader hierarchy is slightly changed. When you start your application you won’t get an URLClassLoader. if your code rely on that … your will need to change it.
third party library
Some third-party libraries depend on part of the jre that is no more accessible. You might need to add instruction to export those when running the unit tests or compiling - for preprocessor, note that you will need to then fork javac.
for the test
for the javac
you can verify which dependencies a jar has by using jdeps
### netty You will need to export the following packages to run the code
- java.base/sun.nio.ch
- java.base/sun.security.util
- java.base/sun.security.x509
- jdk.unsupported/sun.misc
beware though that running in travis-ci it failed with the direct buffer, I had to deactivate the native epoll support.
-Dcassandra.native.epoll.enabled=false
Lombok
Currently as of 1.16.10 Lombok still has issues with java9 as it relies on classes that are not present anymore.
To get the preprocessor as far as you can you will need to add the following to the maven-compiler-plugin configuration.
Osgi bundle
BND seems to work pretty well, there is only 2 config to add.
- _noee, it does not recognise the java version and can’t generate the Require-Capabilities.
- _failok, it fails on the module-info.class being at the root package.