Java – Maven: compile and test at different source levels

I am currently developing a project to run on embedded devices The device runs Java ME JRE (equivalent to Java 1.4)

Because this Maven is configured to compile source code at target level 1.4

Can Maven test phases be run at different source / target levels? Because I can use mockito for unit testing

Thank you, Michael

Solution

The source and target versions can be set separately for the compile and testcompile targets of the Maven compiler plugin You can change settings by defining properties in 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 explicitly configuring the compiler plug-in:

<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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>