is it possibile to create a JAR using the maven-assembly-plugin
, setting a specific compiler version?开发者_JAVA技巧
Thanks
UPDATE:
I meant to say: maven-compiler-plugin
You can not really set the compiler version (as maven uses what's installed), but you can configure source and target level on the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Edit: As khmarbaise points out in the comments, you can specify a different compiler, if you must, but you will have to set fork
to true and specify the path to the executable, which, in the usual case, is not the kind of complication that you'd want. But he's right nonetheless, it's actually possible, and apparently has been since version 2.0 of the maven compiler plugin.
As explained by khmarbaise in the comments, the assembly
plugin is just here to aggregate some project outputs into one package (a ZIP for example). The JVM is not involved in this step.
What you want to achieve exactly? To specify the version of the JVM used to build the JAR, you can simply do that:
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
In this case, you will compile your project using JVM 1.6.
As I am not sure of what you want to achieve, there is also another thing that can be useful for you: you can activate a profile when a specific JVM is used. For example:
<profiles>
<profile>
<activation>
<jdk>1.4</jdk>
</activation>
...
</profile>
</profiles>
in this case, your profile will be activated if you are using JVM 1.4. If you are using Maven 2.1+, you can also use a range of values:
<profiles>
<profile>
<activation>
<jdk>[1.3,1.6)</jdk>
</activation>
...
</profile>
</profiles>
This profile will be activated for all versions between 1.3 (included) and 1.6 (excluded), which means 1.3, 1.4 and 1.5.
Using this, you will be able to configure any plugin for your build depending of the JVM version used.
精彩评论