我目前正在从事一个将在嵌入式设备上运行的项目。该设备运行 Java ME JRE(相当于 Java 1.4)。
因为此 Maven 配置为针对源代码和目标级别 1.4 进行编译。
是否可以在不同的源/目标级别上运行 Maven 测试阶段?因为这样我就可以使用 Mockito 进行单元测试。
最佳答案
可以为 compile 单独设置源版本和目标版本和 testCompile maven compiler plugin 的目标.您可以通过在 pom 中定义属性来更改设置:
<properties>
<maven.compiler.source>1.4</maven.compiler.source>
<maven.compiler.target>1.4</maven.compiler.target>
<maven.compiler.testSource>1.5</maven.compiler.testSource>
<maven.compiler.testTarget>1.5</maven.compiler.testTarget>
</properties>
或者通过显式配置编译器插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
<testSource>1.5</testSource>
<testTarget>1.5</testTarget>
</configuration>
</plugin>
关于java - Maven:在不同的源级别上编译和测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10604007/