Our project uses ant tool to build maven project. We are using java 1.6 and 1.8 for different OS related release. The build works fine for java 1.8 and same is failing when using 1.6 because of versions-maven-plugin which maven downloading is latest and compiled in 1.7.
I tried copying org.codehaus.mojo version plugin of 2.4 in local repository but still maven looking to latest 2.7 version. Is there is way to specify version in ant java task
<java classname="org.codehaus.classworlds.Launcher" fork="true" dir="#{basedir}" resultproperty="#{resultproperty}" failonerror="true">
You can specify the version of versions-maven-plugin in a pluginManagement section, something like:
<pluginManagement>
<plugins>
<plugin>
<artifactId>versions-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
Refer to: Maven2: How to be sure Maven build is using a specific plugin version?
Here is the Maven documentation:
https://maven.apache.org/pom.html#plugin-management
Related
We are using the Tomee Maven Plugin for starting a Tomcat server and running some webapps. We need to use a specific version of Java, which is installed on the local system. Yet the Plugin picks the wrong Java version for starting Tomcat. We then get illegal argument exceptions due to the wrong Java version being used. How can we configure the Tomee Maven plugin to use a specific Java version?
Looking at the documentation there does not seem to be anyway to specify Java Version.
However each version of Tomee supports specific versions of Java, for example Java8/11, etc.
You could select the version that is suitable for your JDK version, as well ensure that your pom.xml has source/target for the specific java version you want:
<properties>
<tomee.version>7.0.2</tomee.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
You could also ensure that your maven compiler plugin uses the appropriate JDK:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
For our project, we have a dependency on another internal library and this library has very very frequent releases.
In the parent application, we want to always use the latest version of this dependency.
With Maven 3.x, I did the following in the pom file
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions-maven-plugin.version}</version>
<configuration>
<includes>
<include>abc.def.xyz:exmaple-dep</include>
</includes>
</configuration>
</plugin>
But when I use the maven to fetch the latest versions, it is fetching latest versions of all dependencies.
I tested this behaviour with the below command:
mvn versions:display-dependency-updates -Dincludes=abc.def.xyz:exmaple-dep
What would be the solution that versions-maven-plugin fetches the latest version only of the given dependency.
The goal versions:display-dependency-updates does not have an include parameter, but versions:use-latest-versions has.
If the syntax does not work, use abc.def.xyz:exmaple-dep:*:*:* instead.
I am currently using jdk version as 11 in my local machine, Set using JAVA_HOME.
I need to run a maven project with java_version as 9.
for doing the same took reference from https://www.baeldung.com/maven-java-version
here is my pom.xml file
<properties>
<java.version>8</java.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
Then i ran the command "mvn clean install" and the jar file generated is having java-version as 11 in its manifest file.
here is the snippet of Manifest file of the gemnerated jar
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.5.0
Built-By: test
Build-Jdk: 11.0.2
Why it is still picking java version as 11, why not 8?
Setting java.version in the POM <properties> section does not change the Java version used to compile with the maven-compiler-plugin. It is instead used by Spring Boot (see Specifying java version in maven - differences between properties and compiler plugin for a related discussion).
Your build is still using the JDK 11 installed on your machine (this is reflected by the manifest attribute Build-Jdk: 11.0.2), however, your code is actually compiled with source and target of Java 8. JDK 11 knows how to compile against earlier versions like JDK 8, so your build is working fine as expected.
You can explicitly change the java version on the go for the particular project so that it gets compliled with the version you want.
Use : JAVA_HOME=/path/to/jdk1.8/ mvn build
Beside above you can explicitly set the version in your pom.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
set fist of all JAVA_HOME then execute the mvn clean install
export JAVA_HOME="C:/Program Files/Java/jdk-11.0.15"
Then excute maven commands
mvn clean install
Note: export command will not work on CMD use gitbash for this command.
I have a maven project using java 10 and I want to edit it in eclipse photon. It more or less works ok, but I do get the warning:
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
Setting the java compiler --> JDK compliance level to 10 in the project properties in eclipse doesn't remove this warning.
Is this an issue with the maven-compiler-plugin? I am currently using version 3.7.0 configured like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
<release>10</release>
<encoding>UTF-8</encoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
Tips on how to configure a maven project using java 10 and eclipse photon would be greatly appreciated.
The issue seems to be with the JRE specified on the build path of your project. Right-click on the project and then go to Properties > Java Build Path > Libraries. There, edit the JRE System Library specified to JRE 10.
Actually, my problem was related to the version of Spring Tool Suite I was using. It turns out that I had upgraded my environment using the update site instead of downloading the new version. I was using Spring Tool Suite 4.7.3a instead of 4.8.0. Using 4.8.0 resolved the issue.
I've created a project in eclipse and added maven dependencies. In Eclipse, it says that I am using JRE 1.5. Everything works fine in Eclipse, for instance, I can run my tests.
When I try to run mvn clean install from the terminal, it gives me the following error.
...generics are not supported in -source 1.3 (use -source 5 or higher to enable generics)...
Its seems that Maven thinks I'm using JRE 1.3 and cannot recognize generics or for-each loops.
How can I:
Validate my assumption that maven is using the wrong version.
Get Maven to compile my project.
Specify the correct version of your JRE in the Maven compiler plugin, by default your pom.xml file will inherit the compiler-plugin from the Maven super pom.xml which targets the 1.3 JRE.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>