【问题标题】:Maven: skip test-compile in the life cycle?Maven:在生命周期中跳过测试编译?
【发布时间】:2011-08-12 16:32:56
【问题描述】:

我有一个项目,我设置为使用 test-jar 和普通 jar 通过使用此设置来构建:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这个问题是每当我在 pom 中升级项目版本时,我都需要使用测试进行构建,否则 maven 将无法在 test-compile 期间找到具有正确版本的 test-jar短语。很多时候我只想跳过测试,但由于缺少测试罐,test-compilephrase 将失败。

我尝试使用-Dmaven.test.skip=true,但这似乎并没有跳过test-compile 阶段。有没有办法跳过这个?

【问题讨论】:

    标签: testing build maven compilation skip


    【解决方案1】:

    如果你想跳过编译测试源,可以尝试适当配置maven compiler plugin。但不建议这样做。

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

    【讨论】:

    • 如果可能的话,我实际上正在寻找一个命令行参数。
    • @fei。如maven.apache.org/general.html#skip-test 中所述,maven.test.skip=true 跳过测试编译和执行。如果这没有发生,您可以使用日志更新您的问题。
    • 我将我的 ID 设置为 default-testCompile 以外的其他值,这将无法正常工作。为什么需要此特定 ID?
    • @Ungeheuer 您正在尝试覆盖已为 maven-compiler-plugin 定义的执行定义。我这样做的方式是&lt;execution&gt;&lt;id&gt;default-testCompile&lt;/id&gt;&lt;phase/&gt;&lt;/execution&gt;,它将它与任何阶段解除绑定,因此它甚至不会显示为已跳过。我在一些项目中使用它来覆盖在父 POM 中为默认构建配置文件定义的各种检查相关插件。
    【解决方案2】:
    $ mvn clean install -Dmaven.test.skip=true \
          -Dmaven.site.skip=true -Dmaven.javadoc.skip=true
    

    【讨论】:

    • 有一个简短的解释通常比只有代码的答案更好。
    • 不需要这个参数 -Dmaven.javadoc.skip=true - 它适用于我的几个参数来跳过站点登台和测试
    • 我最近才意识到的一件事:-Dmaven.test.skip=true-DskipTests=true 不是一回事。
    • 详细说明 Sridhar 所说的:skipTests 只跳过测试的执行,而maven.test.skip 跳过编译和执行。
    • @FWDekker 很好的解释!
    【解决方案3】:

    只需添加 -Dmaven.test.skip 。它甚至不会编译测试

    【讨论】:

    • 是的,这个测试不会运行,但测试文件会编译。但只给出这个不会编译测试文件
    【解决方案4】:

    这是我来自https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html的工作命令

    您可以使用以下命令跳过正在运行的测试

    mvn clean install -DskipTests

    如果您绝对必须,您也可以使用 ma​​ven.test.skip 属性跳过编译测试。 ma​​ven.test.skip 获得了 Surefire、Failsafe 和 Compiler Plugin 的荣誉。

    mvn clean install -Dmaven.test.skip=true -DskipTests

    【讨论】:

    • 这不会运行测试,但仍会编译它们。
    【解决方案5】:

    有点晚了,但要简明扼要地概括——

    补充@Sridhar@FWDekker所说的,

    mvn clean install -DskipTests=true 将跳过测试执行

    mvn clean install -Dmaven.test.skip 将跳过测试的编译和执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 2011-07-31
      • 2012-01-05
      • 2016-12-31
      • 2019-02-12
      • 2012-11-29
      相关资源
      最近更新 更多