I want to use Java 11 syntax in my unit tests, but my 'main' code needs to be compiled for Java 8 since my production environment only has JDK 8 installed.
Is there a way of doing this with the maven-compiler-plugin? My Jenkins server has Java 11 installed.
I will accept the risk that I can accidental use Java 11 specific functionality in my production code.
Chances are that it just runs fine with Java 11. Hint: You can speed up multi-module Maven projects by using parallel builds, e.g. mvn -T 4 compile compiles all modules in parallel on 4 CPU cores.
The class files created by Java 8 are still executable in Java 11; however, there have been other changes in the Java runtime (library changes, etc.) that might require modification of the code. These modifications may be made in Java 8 and compiled with Java 8 making it compatible with the Java 11 runtime.
In Maven compile and testCompile goals are different. And Maven even has parameters for testCompile: testTarget and testSource. So:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> <testSource>1.8</testSource> <testTarget>1.8</testTarget> </configuration> </plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With