maven - 使用 Maven 3 是否可以使用与编译插件中设置不同的 java 版本来运行 JUNIT 测试?

标签 maven maven-3 junit4

我的项目必须使用 JAVA 1.3 构建,因此我使用以下编译插件:

<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <source>1.3</source>
        <target>1.3</target>
    </configuration>
</plugin>

。但是,在构建过程中,我需要执行 JUNIT4 测试,因此我需要 sunfire 插件才能使用 java 1.6。这在 Maven 3 中可能吗?

最佳答案

将您的插件配置更改为如下所示:

<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
        <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <source>1.3</source>
                <target>1.3</target>
            </configuration>
        </execution>
        <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </execution>
    </executions>
</plugin>

关于maven - 使用 Maven 3 是否可以使用与编译插件中设置不同的 java 版本来运行 JUNIT 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13232274/

相关文章:

maven - gmaven 从 groovy 脚本设置 maven 属性

java - 将接缝预订示例与 jboss 链接时出错

spring - junit 测试用例事务未提交 - 没有错误

selenium - 断言确认的 webdriver 等效项是什么?

java - 如何在 RxJava 2 中使用 TestObserver 对对象列表进行单元测试?

maven-2 - 如何抑制Maven程序集插件跳过已添加的文件?还是允许覆盖?

Java 9 在创建 Tomcat 服务器时抛出新错误 [ExecutionException caused by ZipException]

maven - 无法获得完整的 Maven 原型(prototype)列表

java - 从 Mojo 获取项目的 Artifact 依赖项列表

maven - Jenkins 中的增量构建