Maven:在生命周期中跳过测试编译?

发布于 2024-11-03 10:54:23 字数 755 浏览 5 评论 0原文

我有一个项目,我设置使用此设置使用 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-jar,test-compile 短语将会失败。

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

I have project that I set to build with the test-jar and normal jar by using this setting:

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

The problem with this is whenever I upgrade the project version in the pom, I need to do a build with the tests, otherwise maven won't be able to find the test-jar with the correct version during the test-compile phrase. A lot of time I would just want to skip the tests, but due to the test-jar missing, the test-compilephrase will fail.

I tried to use -Dmaven.test.skip=true, but that doesn't seem to skip the test-compile phase. Is there a way to skip this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半山落雨半山空 2024-11-10 10:54:23
$ mvn clean install -Dmaven.test.skip=true \
      -Dmaven.site.skip=true -Dmaven.javadoc.skip=true
$ mvn clean install -Dmaven.test.skip=true \
      -Dmaven.site.skip=true -Dmaven.javadoc.skip=true
吝吻 2024-11-10 10:54:23

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

        <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>

If you want to skip the compilation of test sources, you can try configuring the maven compiler plugin suitably. This is not recommended though.

        <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>
慵挽 2024-11-10 10:54:23

有点晚了,但是简单而准确地总结一下 -

添加 @Sridhar@FWDekker 说,

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

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

Little Late, But to summarise in short and be precise -

Adding to what @Sridhar and @FWDekker said,

mvn clean install -DskipTests=true will just skip the Tests Execution

mvn clean install -Dmaven.test.skip will skip both compilation and execution of Tests.

后来的我们 2024-11-10 10:54:23

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

Just Add -Dmaven.test.skip . It will Not even compile test

古镇旧梦 2024-11-10 10:54:23

这是我的工作命令 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 和编译器插件的认可。

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

Here is my working command from https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html

You can skip running tests with the following command

mvn clean install -DskipTests

If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文