Determine the actual java version used in maven build - java

Complementary to this question, how to determine actual java version used in mvn compile?
I am compiling FasterXML/jackson-databind as follows, but can't be sure of the java version:
$ git clone https://github.com/FasterXML/jackson-databind.git
$ cd jackson-databind
$ mvn compile
$ javap -verbose ./target/classes/com/fasterxml/jackson/databind/PropertyNamingStrategy.class | grep "major"
major version: 52
So according to this post, the java version is 1.8.
But when I grep the pom.xml I don't see that:
$ grep -wn "source" pom.xml
245: <id>add-test-source</id>
248: <goal>add-test-source</goal>
252: <source>src/test-jdk14/java</source>
265: <source>14</source>
I only see java 14 (?) What am I missing?

It's in the new release tag, not the source or compile -
You can reference it using the maven user property
NB Release overrides source and target values -
e.g. having source = 1.8, and target = 1.8, with release = 14,
compiles and releases in JDK 14
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<release>${maven.compiler.source}</release>

The parent POM is jackson-base which does set the java version : https://github.com/FasterXML/jackson-bom/blob/e60567a0e778f749d9e39e2c245486a44fbc52f9/base/pom.xml
<javac.src.version>1.8</javac.src.version>
<javac.target.version>1.8</javac.target.version>
<maven.compiler.source>${javac.src.version}</maven.compiler.source>
<maven.compiler.target>${javac.target.version}</maven.compiler.target>
You can inspect the fully evaluated POM with all the parents/dependencies/plugins/properties/etc using mvn help:effective-pom

The version that is used by maven can be found in POM file like:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
or alternatively
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

Related

Java level issue with Maven compilation

I'm facing a weird issue. In Maven I am setting the Java level to 1.8. In my code I have some Java 11 syntax, namely:
final Optional<Stock> stock = stockRepo.findById(id);
if (stock.isEmpty()) {
throw new StockNotFoundException("Stock not found, id: " + id);
}
The code gets compiled just OK, I was expecting it to fail.
In the pom I have:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
...
Maven prints the following logs with -X option
[DEBUG] Command line options:
[DEBUG] -d /Users/user/Desktop/java_dev/projects/stockapp-spring-boot/stockapp/target/classes -classpath /Users/user/Desktop/java_dev/projects/stockapp-spring-boot/stockapp/target/classes:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.6.2/spring-boot-starter-web-2.6.2.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter/2.6.2/spring-boot-starter-2.6.2.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot/2.6.2/spring-boot-2.6.2.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.2/spring-boot-autoconfigure-2.6.2.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.6.2/spring-boot-starter-logging-2.6.2.jar:/Users/user/.m2/repository/ch/qos/logback/logback-classic/1.2.9/logback-classic-1.2.9.jar:/Users/user/.m2/repository/ch/qos/logback/logback-core/1.2.9/logback-core-1.2.9.jar:/Users/user/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.17.0/log4j-to-slf4j-2.17.0.jar:/Users/user/.m2/repository/org/apache/logging/log4j/log4j-api/2.17.0/log4j-api-2.17.0.jar:/Users/user/.m2/repository/org/slf4j/jul-to-slf4j/1.7.32/jul-to-slf4j-1.7.32.jar:/Users/user/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/user/.m2/repository/org/yaml/snakeyaml/1.29/snakeyaml-1.29.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.6.2/spring-boot-starter-json-2.6.2.jar:/Users/user/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.13.1/jackson-datatype-jdk8-2.13.1.jar:/Users/user/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.13.1/jackson-datatype-jsr310-2.13.1.jar:/Users/user/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.13.1/jackson-module-parameter-names-2.13.1.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.6.2/spring-boot-starter-tomcat-2.6.2.jar:/Users/user/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.56/tomcat-embed-core-9.0.56.jar:/Users/user/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.56/tomcat-embed-websocket-9.0.56.jar:/Users/user/.m2/repository/org/springframework/spring-web/5.3.14/spring-web-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-beans/5.3.14/spring-beans-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-webmvc/5.3.14/spring-webmvc-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-context/5.3.14/spring-context-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-expression/5.3.14/spring-expression-5.3.14.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-security/2.6.2/spring-boot-starter-security-2.6.2.jar:/Users/user/.m2/repository/org/springframework/spring-aop/5.3.14/spring-aop-5.3.14.jar:/Users/user/.m2/repository/org/springframework/security/spring-security-config/5.6.1/spring-security-config-5.6.1.jar:/Users/user/.m2/repository/org/springframework/security/spring-security-core/5.6.1/spring-security-core-5.6.1.jar:/Users/user/.m2/repository/org/springframework/security/spring-security-crypto/5.6.1/spring-security-crypto-5.6.1.jar:/Users/user/.m2/repository/org/springframework/security/spring-security-web/5.6.1/spring-security-web-5.6.1.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.6.2/spring-boot-starter-data-jpa-2.6.2.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.6.2/spring-boot-starter-aop-2.6.2.jar:/Users/user/.m2/repository/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.6.2/spring-boot-starter-jdbc-2.6.2.jar:/Users/user/.m2/repository/com/zaxxer/HikariCP/4.0.3/HikariCP-4.0.3.jar:/Users/user/.m2/repository/org/springframework/spring-jdbc/5.3.14/spring-jdbc-5.3.14.jar:/Users/user/.m2/repository/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar:/Users/user/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/Users/user/.m2/repository/org/hibernate/hibernate-core/5.6.3.Final/hibernate-core-5.6.3.Final.jar:/Users/user/.m2/repository/org/jboss/logging/jboss-logging/3.4.2.Final/jboss-logging-3.4.2.Final.jar:/Users/user/.m2/repository/net/bytebuddy/byte-buddy/1.11.22/byte-buddy-1.11.22.jar:/Users/user/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/user/.m2/repository/org/jboss/jandex/2.2.3.Final/jandex-2.2.3.Final.jar:/Users/user/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/user/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar:/Users/user/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.5/jaxb-runtime-2.3.5.jar:/Users/user/.m2/repository/org/glassfish/jaxb/txw2/2.3.5/txw2-2.3.5.jar:/Users/user/.m2/repository/com/sun/istack/istack-commons-runtime/3.0.12/istack-commons-runtime-3.0.12.jar:/Users/user/.m2/repository/org/springframework/data/spring-data-jpa/2.6.0/spring-data-jpa-2.6.0.jar:/Users/user/.m2/repository/org/springframework/data/spring-data-commons/2.6.0/spring-data-commons-2.6.0.jar:/Users/user/.m2/repository/org/springframework/spring-orm/5.3.14/spring-orm-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-tx/5.3.14/spring-tx-5.3.14.jar:/Users/user/.m2/repository/org/slf4j/slf4j-api/1.7.32/slf4j-api-1.7.32.jar:/Users/user/.m2/repository/org/springframework/spring-aspects/5.3.14/spring-aspects-5.3.14.jar:/Users/user/.m2/repository/org/springframework/boot/spring-boot-starter-validation/2.6.2/spring-boot-starter-validation-2.6.2.jar:/Users/user/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/9.0.56/tomcat-embed-el-9.0.56.jar:/Users/user/.m2/repository/org/hibernate/validator/hibernate-validator/6.2.0.Final/hibernate-validator-6.2.0.Final.jar:/Users/user/.m2/repository/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar:/Users/user/.m2/repository/org/liquibase/liquibase-core/4.5.0/liquibase-core-4.5.0.jar:/Users/user/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar:/Users/user/.m2/repository/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar:/Users/user/.m2/repository/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.13.1/jackson-module-jaxb-annotations-2.13.1.jar:/Users/user/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.13.1/jackson-annotations-2.13.1.jar:/Users/user/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.1/jackson-core-2.13.1.jar:/Users/user/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.13.1/jackson-databind-2.13.1.jar:/Users/user/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/Users/user/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar:/Users/user/.m2/repository/org/springframework/spring-core/5.3.14/spring-core-5.3.14.jar:/Users/user/.m2/repository/org/springframework/spring-jcl/5.3.14/spring-jcl-5.3.14.jar:/Users/user/.m2/repository/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar:/Users/user/.m2/repository/org/mapstruct/mapstruct-processor/1.3.1.Final/mapstruct-processor-1.3.1.Final.jar:/Users/user/.m2/repository/org/mapstruct/mapstruct/1.3.1.Final/mapstruct-1.3.1.Final.jar: -sourcepath /Users/user/Desktop/java_dev/projects/stockapp-spring-boot/stockapp/src/main/java:/Users/user/Desktop/java_dev/projects/stockapp-spring-boot/stockapp/target/generated-sources/annotations: -s /Users/user/Desktop/java_dev/projects/stockapp-spring-boot/stockapp/target/generated-sources/annotations -g -nowarn -target 1.8 -source 1.8 -encoding UTF-8
Any clue?
There is no specific Java 11 syntax in the provided code. There is a use of an API not present in JDK8, so if you try compiling this with JDK8 it will fail. But you are probably compiling with JAVA_HOME set to JDK11+.
The syntax difference would be something like:
final var stock = stockRepo.findById(id);

How to specify java version when I use mvn package command without change environment path

My environment java version is jdk8,Now I want use Maven command mvn package to compile some project.How to specify java version(like java11) to compile it whitout change environment path,because java version is a dynamic arguments in my process
Compiling Sources Using A Different JDK
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>11</compilerVersion>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Well the side effect is we have to edit the pom.xml file.
We may keep different version of pom.xml file, like pom-java11.xml, pom-java17.xml
mvn -f <other pom file> for your task, like mvn -f pom-java11.xml ...
In pom.xml you can define the version of JDK
Like
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.1</spring-cloud.version>
</properties>

How can I change my system Library from jre to jdk in java Maven [duplicate]

I am trying to build a Hudson plugin I've modified and it requires jdk1.6. This is fine, but I don't see how I can tell maven where the different jdk is. I've found few mentions on the internet but they don't seem to apply to me. Some suggest adding some config to .m2/settings.xml but I don't have a settings.xml. Plus, I don't want to use 1.6 for all maven builds.
One kink is I am using mvn in cygwin, if that matters at all. It appears I should be able to make the specification in the project pom file, but the existing pom is pretty bare.
So bottom line is, is there a way to specify a jdk for a single invocation of maven?
So bottom line is, is there a way to specify a jdk for a single invocation of maven?
Temporarily change the value of your JAVA_HOME environment variable.
Seems that maven now gives a solution here : Compiling Sources Using A Different JDK
Let's say your JAVA_HOME points to JDK7 (which will run maven processes)
Your pom.xml could be :
<build>
<plugins>
<!-- we want JDK 1.6 source and binary compatiblility -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- ... -->
<!-- we want sources to be processed by a specific 1.6 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_6_HOME}/bin/javac</executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
If your developpers just add (and customize) the following lines in their settings.xml, your pom will be platform independant :
<settings>
[...]
<profiles>
[...]
<profile>
<id>compiler</id>
<properties>
<JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
<JAVA_1_6_HOME>C:\Program Files\Java\j2sdk1.6.0_18</JAVA_1_6_HOME>
</properties>
</profile>
</profiles>
[...]
<activeProfiles>
<activeProfile>compiler</activeProfile>
</activeProfiles>
</settings>
compile:compile has a user property that allows you to specify a path to the javac.
Note that this user property only works when fork is true which is false by default.
$ mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable=/path/to/the/javac compile
You might have to double quote the value if it contains spaces.
> mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable="C:\...\javac" compile
See also Maven custom properties precedence.
As u said "Plus, I don't want to use 1.6 for all maven builds."....So better I will say modify your pom file and specify which jdk version to use.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>
</plugins>
</build>
It will ensure that your particular project uses that version of jdk.
I say you setup the JAVA_HOME environment variable like Pascal is saying:
In Cygwin if you use bash as your shell should be:
export JAVA_HOME=/cygdrive/c/pathtothejdk
It never harms to also prepend the java bin directory path to the PATH environment variable with:
export PATH=${JAVA_HOME}/bin:${PATH}
Also add maven-enforce-plugin to make sure the right JDK is used. This is a good practice for your pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>1.6</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please, see Maven Enforcer plugin – Usage.
If you have installed Java through brew in Mac then chances are you will find your Java Home Directory here:
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
The next step now would be to find which Java Home directory maven is pointing to. To find it type in the command:
mvn -version
The fields we are interested in here is:
Java version and runtime.
Maven is currently pointing to Java 13. Also, you can see the Java Home path under the key runtime, which is:
/usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
To change the Java version of the maven, we need to add the Java 8 home path to the JAVA_HOME env variable.
To do that we need to run the command:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
in the terminal.
Now if we check the maven version, we can see that it is pointing to Java 8 now.
The problem with this is if you check the maven version again in the new terminal, you will find that it is pointing to the Java 13. To avoid this I would suggest adding the JAVA_HOME variable in the ~/.profile file.
This way whenever your terminal is loading it will take up the value you defined in the JAVA_HOME by default. This is the line you need to add in the ~/.profile file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
You can open up a new terminal and check the Maven version, (mvn -version) and you will find it is pointing to the Java 8 this time.
I know its an old thread. But I was having some issues with something similar to this in Maven for Java 8 compiler source. I figured this out with a quick fix mentioned in this article thought I can put it here and maybe can help others:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Maven uses variable $JAVACMD as the final java command, set it to where the java executable is will switch maven to different JDK.
You could also set the JDK for Maven in a file in your home directory ~/.mavenrc:
JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home'
This environment variable will be checked by the mvn script and used when present:
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
https://github.com/CodeFX-org/mvn-java-9/tree/master/mavenrc
Hudson also allows you to define several Java runtimes, and let you invoke Maven with one of these. Have a closer look on the configuration page.
Yet another alternative to manage multiple jdk versions is jEnv
After installation, you can simply change java version "locally" i.e. for a specific project directory by:
jenv local 1.6
This will also make mvn use that version locally, when you enable the mvn plugin:
jenv enable-plugin maven
I update my ~/.m2/settings.xml
<settings>
<profiles>
<profile>
<id>j8</id>
<profile>
<id>j8</id>
<properties>
<maven.compiler.fork>true</maven.compiler.fork>
<maven.compiler.executable>${env.JAVA_HOME8}/bin/javac.exe</maven.compiler.executable>
</properties>
</profile>
<profile>
<id>j11</id>
<properties>
<maven.compiler.fork>true</maven.compiler.fork>
<maven.compiler.executable>${env.JAVA_HOME11}/bin/javac.exe</maven.compiler.executable>
</properties>
</profile>
</profiles>
<settings>
For build with Java8 I run mvn with properties:
mvn compile -Pj8
and for Java 11
mvn compile -Pj11
If nothing else works and even after you set JAVA_HOME to a correct path, check if there is no override of the JAVA_HOME path in <user>/.mavenrc!
As a further tip, the mvn file is a bash script (on Linux).. so if necessary you can inspect the source [and change it].
I had build problem with maven within Eclipse on Windows 7.
Though I observed mvn build was running just fine from command line.
mvn -T 5 -B -e -X -U -P test clean install -Dmaven.surefire.debug --settings ..\..\infra-scripts\maven-conf\settings.xml > output.log
Eclipse was considering as default JVM a JRE installation instead of JDK so it was failing on compilation.
I added to eclipse.ini following line:
-vm
C:\Program Files (x86)\Java\jdk1.8.0_25\bin
Also when starting from eclipse I used in "Goals" section following list:
-T 5 -B -e -X -U -P test clean install -Dmaven.surefire.debug --settings ..\..\infra-scripts\maven-conf\settings.xml
Compilation error got solved.
For Java 9 :
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

Unable to build Java project targeting JDK 11, Invalid target release 11

I have JDK 11 installed along with Maven 3.6.2 and am using error prone to compile my Java maven projects. With this configuration:
pom.xml:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<useIncrementalCompilation>false</useIncrementalCompilation>
<compilerArgs>
<arg>-Xep:ParameterName:OFF</arg>
</compilerArgs>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${google.error.prone.version}</version>
</dependency>
</dependencies>
</plugin>
I get this error:
CompilerException: InvocationTargetException: invalid target release: 11
I tried following this information:
Unable to compile simple Java 10 / Java 11 project with Maven
However, upgrading ASM did not change anything.
As per the maven documentation:
The Compiler Plugin is used to compile the sources of your project.
Since 3.0, the default compiler is javax.tools.JavaCompiler (if you
are using java 1.6) and is used to compile Java sources. If you want
to force the plugin using javac, you must configure the plugin option
forceJavacCompilerUse.
Also note that at present the default source setting is 1.6 and the
default target setting is 1.6, independently of the JDK you run Maven
with. You are highly encouraged to change these defaults by setting
source and target as described in Setting the -source and -target of
the Java Compiler.
After changing the source and target to 11 as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
the above mentioned error of invalid java 11 version didn't appear
I put in properties this: <java.version>1.11</java.version> and in maven compiler pugin of this way: <source>11</source> <target>11</target>.
It works for me.

maven-compiler-plugin broken on linux?

I have a maven project. In the pom.xml file the following is stated:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
</build>
...
AFAIK this is correct, it should build against JDK 7.
I run a Debian based Linux dist and when I do mvn clean install it seems to always build against the javac version I have set in my os.
I've tried reading up on what the plugin exactly does https://maven.apache.org/plugins/maven-compiler-plugin/, but it doesn't really state how.
An example is I have javac 8 running on my os. When I invoke mvn clean install, the project compiles against JDK 8 and not JDK 7 as stated in the pom.xml. Why is this?
By default the maven-compiler-plugin uses %JAVA_HOME%/bin/javac to compile, unless:
you set the executable-parameter to a different location
you use Toolchains, which seems to match your requirements, i.e a different Java Runtime for Maven compared to the JDK for the maven-compiler-plugin.
Source and target settings are just passed to the javac compiler as parameters. The javac installed on the machine is used.

Categories

Resources