Maven project dependency on JDK version

I have projects that need to be built using a specific version of the JDK.

The problem is not in the source and target parameters, but in the banks of the runtime used at compile time. In some cases, I get a compilation error if I try to compile with the wrong JDK, but sometimes the build is successful, and I get runtime errors when using banners.

For example, in eclipse, I have the ability to set the runtime for a project in a .classpath file.

Is there a way to handle this situation in maven?

What I would like to have is the ability to handle the JRE dependency, like the other project dependencies in the POM file.

UPDATE:

The decision I made was the best when I asked this question, so I won’t change it. Meanwhile, a new solution to such problems was introduced: the Maven Toolchain . Follow the link for more information.

+7
java maven-2 dependencies
source share
3 answers

I found this article:

http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <verbose>true</verbose> <fork>true</fork> <executable>${JAVA_1_4_HOME}/bin/javac</executable> <compilerVersion>1.3</compilerVersion> </configuration> </plugin> </plugins> [...] </build> [...] </project> 
+2
source share

I have projects that need to be built using a specific version of the JDK.

You can use the Maven Enforcer plugin to ensure that a specific version of the JDK is used:

 <project> [...] <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.5</version> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project> 

But I'm not sure that I really understood the question. If this is not what you want, perhaps you can declare your specific JDK dependencies in profiles and use an activation trigger based on the JDK version. For example:

 <profiles> <profile> <activation> <jdk>1.5</jdk> </activation> ... </profile> </profiles> 

This configuration starts the profile when the JDK version starts with "1.5".

+2
source share

I believe that this can be solved with the following plugin in your pom:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

Here you configure version 1.6 or write your own version

+1
source share

All Articles