如何让 maven-release-plugin 跳过我的测试?

发布于 2024-12-23 07:56:21 字数 288 浏览 5 评论 0原文

如何在不触发测试的情况下运行 maven-release-plugin?

我已经尝试

-Dmaven.test.skip=true 

-DskipTests 

......

-DpreparationGoals=clean

但没有任何效果。

是的,我知道如果测试未通过,我不应该发布,但我无法控制让我的同事编写可靠的测试。

How can I get the maven-release-plugin to run without triggering the tests?

I have tried

-Dmaven.test.skip=true 

and

-DskipTests 

and

-DpreparationGoals=clean

...yet none work.

Yes, I know I shouldn't release if the tests don't pass, but I don't have control over making my coworkers write reliable tests.

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

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

发布评论

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

评论(7

冷默言语 2024-12-30 07:56:21

-Darguments="-DskipTests" 是您想要的,或者在 pom.xml 中显式配置分叉执行。

-Darguments="-DskipTests" is what you want, or explicitly configuring the forked executions in the pom.

溺深海 2024-12-30 07:56:21

-Darguments="..." 将参数传递给分叉的 Maven 进程,但重要的是要意识到这里使用了两个不同的开关。 -DskipTests 强制 maven 不运行任何测试,但测试仍会编译(如果您对测试 jar 类型有任何依赖项,这一点很重要)。 -Dmaven.test.skip=true 强制 maven 甚至不编译测试,这意味着不会生成任何测试 jar。

因此,您必须使用 -Darguments,但要跳过正在运行的测试,请仅使用 skipTests,要停止编译,请使用 maven.test.skip

-Darguments="..." passes arguments to the forked maven process, but it is important to realise that there are two different switches being used here. The -DskipTests forces maven to not run any tests, but the tests are still compiled (this is important if you have any dependencies on a test-jar type). The -Dmaven.test.skip=true forces maven to not even compile the tests, which means that any test-jars will not be generated.

So, you must use -Darguments, but to skip tests running use only skipTests, to stop them compiling use maven.test.skip.

ゞ花落谁相伴 2024-12-30 07:56:21

如果您只想跳过集成测试,可以这样做:

-Darguments="-DskipITs"

If you just want to skip integration tests, this will do it:

-Darguments="-DskipITs"
凉墨 2024-12-30 07:56:21

您有太多不同的选择来避免和跳过发布插件的测试

  • 第一个是通过提供 -Darguments 作为 cli 上的参数传递给发布目标或阶段:

例如: mvn -X -Darguments="-Dmaven. javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true" -P release-mode release:prepare

-第二个是执行这些构建中 pom.xml 上的参数如下所示:

                <plugin>    
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.scm</groupId>
                            <artifactId>maven-scm-provider-gitexe</artifactId>
                            <version>1.9.4</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <skip>true</skip>
                        <skipTests>true</skipTests>
                        <preparationGoals>clean validate</preparationGoals>
                        <arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true</arguments>
                        <useReleaseProfile>false</useReleaseProfile>
                        <releaseProfiles>release-mode</releaseProfiles>
                        <tagNameFormat>TEST-@{project.version}</tagNameFormat>
                    </configuration>
                </plugin>

请注意,第二个方法会覆盖第一个方法。

我建议您首先在单个操作上准备发布,然后您可以编辑工作目录中的release.properties 文件,并查看exec.additionalArguments 属性(如果您的参数存在)。它看起来像:exec.additionalArguments=-Dmaven.javadoc.skip\=true -Dmaven.test.skipTests\=true -Dmaven.test.skip\=true -P release-mode

之后就可以执行释放了。

you have too differents choices to avoid and skip tests with the release plugin

  • The first is to pass as argument on cli to the release goal or phases by providing a -Darguments:

exemple: mvn -X -Darguments="-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true" -P release-mode release:prepare

-The second is to perform thoses arguments on your pom.xml in the build like this:

                <plugin>    
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.scm</groupId>
                            <artifactId>maven-scm-provider-gitexe</artifactId>
                            <version>1.9.4</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <skip>true</skip>
                        <skipTests>true</skipTests>
                        <preparationGoals>clean validate</preparationGoals>
                        <arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true</arguments>
                        <useReleaseProfile>false</useReleaseProfile>
                        <releaseProfiles>release-mode</releaseProfiles>
                        <tagNameFormat>TEST-@{project.version}</tagNameFormat>
                    </configuration>
                </plugin>

Note that the second method override the first.

I recommanded you to prepare release first on a single action and then you can edit the release.properties file on the working directorie and look the exec.additionalArguments properties if your arguments are there. It will look like: exec.additionalArguments=-Dmaven.javadoc.skip\=true -Dmaven.test.skipTests\=true -Dmaven.test.skip\=true -P release-mode.

After you can perform the release.

凉风有信 2024-12-30 07:56:21

我通过简单地将 configuration preparationGoals 添加到 clean 来避免运行 verify 目标:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>
  <configuration>
    <preparationGoals>clean</preparationGoals> <!-- See here -->
  </configuration>
</plugin>

I have managed to avoid running the verify goal by simply adding the configuration preparationGoals to clean:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>
  <configuration>
    <preparationGoals>clean</preparationGoals> <!-- See here -->
  </configuration>
</plugin>
他是夢罘是命 2024-12-30 07:56:21

使用以下参数跳过测试

-Darguments="-DskipTests"

默认跳过

 [...]
  <properties>
    <skipTests>true</skipTests>
  </properties>
  [...]

Use the following argument to skip test

-Darguments="-DskipTests"

or

alternatively skipping by default

 [...]
  <properties>
    <skipTests>true</skipTests>
  </properties>
  [...]
南街九尾狐 2024-12-30 07:56:21

当您使用 gitflow-maven-plugin 跳过测试时,请在配置属性中使用 skipTestProject : true (默认值为 false)。文档中详细描述: https://aleksandr- m.github.io/gitflow-maven-plugin/release-finish-mojo.html

示例:

    <plugin>
        <groupId>com.amashchenko.maven.plugin</groupId>
        <artifactId>gitflow-maven-plugin</artifactId>
        <version>${gitflow.plugin.version}</version>
        <configuration>
            <skipTestProject>true</skipTestProject>
        </configuration>
    </plugin>

When You use gitflow-maven-plugin to skip tests use skipTestProject : true inside configuration property (default value is false). Described in details in documentation : https://aleksandr-m.github.io/gitflow-maven-plugin/release-finish-mojo.html

example :

    <plugin>
        <groupId>com.amashchenko.maven.plugin</groupId>
        <artifactId>gitflow-maven-plugin</artifactId>
        <version>${gitflow.plugin.version}</version>
        <configuration>
            <skipTestProject>true</skipTestProject>
        </configuration>
    </plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文