2012-05-15 61 views
10

我目前正在研究一个将在嵌入式设备上运行的项目。该设备运行Java ME JRE(与Java 1.4相当)。Maven:编译和测试不同源级

因为这个maven被配置为编译源&目标级别1.4。

是否可以在不同的源/目标级别上运行Maven测试阶段?因为这样我可以使用Mockito进行单元测试。

回答

19

源和目标版本可以分别为maven compiler plugincompiletestCompile目标进行设定。

<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> 
您可以通过在你的POM定义属性更改设置
相关问题