問題描述
我目前正在開發一個將在嵌入式設備上運行的項目.該設備運行 Java ME JRE(相當于 Java 1.4).
I am currently working on a project which will run on an embedded device. The device runs a Java ME JRE (comparable to Java 1.4).
因為這個 maven 被配置為編譯為 source &目標等級 1.4.
Because of this maven is configured to compile for source & target level 1.4.
是否可以在不同的源/目標級別上運行 Maven 測試階段?因為這樣我可以使用 Mockito 進行單元測試.
Is it possible to run the maven test phase on a different source/target level? Because this way I could use Mockito for unit-testing.
推薦答案
編譯和testCompile maven 編譯器插件 的目標.您可以通過在 pom 中定義屬性來更改設置:
The source and target versions can be set separately for the compile and testCompile goals of the maven compiler plugin. You can change the settings either by defining properties in your 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>
或者通過編譯器插件的顯式配置:
Or by explicit configuration of the compiler plugin:
<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>
這篇關于Maven:在不同的源代碼級別上編譯和測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!