My Maven项目是一个将在Java 6和Java 7项目中使用的jar。 所以我希望有不同的工件可以像这样使用:
<dependency>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<classifier>jdk6</classifier>
</dependency>
我也希望他们一次性建成。因此,配置文件可能不是可行的方法。 我尝试使用多个插件执行。
首先,我创建了两个单独的构建目录:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>createClassesDir</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.outputDirectory}/jdk6" />
<mkdir dir="${project.build.outputDirectory}/jdk7" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
然后我尝试在两个目录中配置maven-compiler-plugin两次构建:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>jdk6</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<fork>true</fork>
<compilerArguments>
<d>${project.build.outputDirectory}/jdk6</d>
</compilerArguments>
</configuration>
</execution>
<execution>
<id>jdk7</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<compilerArguments>
<d>${project.build.outputDirectory}/jdk7</d>
</compilerArguments>
</configuration>
</execution>
</executions>
</plugin>
但我无法让它发挥作用。它从未编译第二次,因为源文件已经编译:
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ example ---
[INFO] Compiling 1 source file to [...]/example/target/classes
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (jdk6) @ example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (jdk7) @ example ---
[INFO] Nothing to compile - all classes are up to date
你知道我如何为这两种环境编译吗?