如何停止Maven的验证阶段重建工件? [英] How to stop Maven's verify phase rebuilding the artifact?

查看:181
本文介绍了如何停止Maven的验证阶段重建工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下使用Maven构建的Java项目:

Imagine a Java project built using Maven for which I have:


  • 一些快速运行的单元测试:

    • 开发人员应在提交之前运行

    • 我的CI服务器(Hudson,FWIW)应该在检测到新提交时运行, / li>
    • some fast-running unit tests that:
      • developers should run before committing
      • my CI server (Hudson, FWIW) should run upon detecting a new commit, giving almost instant feedback in case of failures

      • 选择,例如

      这似乎是一个典型的场景。目前,我正在运行:

      This seems like a typical scenario. Currently, I'm running:


      • 在测试阶段进行单元测试

      • 验证阶段的验证测试

      配置了两个配置的CI作业,都指向项目的VCS分支:

      There are two CI jobs configured, both pointing to the project's VCS branch:


      1. 提交阶段运行mvn package(编译和单元测试代码,构建工件),如果成功, li>
      2. 执行mvn verify(设置,运行和删除验收测试)的自动验收测试

      问题是作业2单元测试并再次构建被测工件(因为验证阶段自动调用软件包阶段)。这是不希望的,因为几个原因(在重要性降低):

      The problem is that job 2 unit tests and builds the artifact-under-test all over again (because the verify phase automatically invokes the package phase). This is undesirable for several reasons (in decreasing importance):


      • 作业2创建的工件可能与作业1 (例如,如果在此期间有一个新的提交)

      • 延长反馈循环给开发者提交(即花费更长的时间,他们发现他们打破了构建) / li>
      • 会浪费CI服务器上的资源

      所以我的问题是,如何配置作业2使用由作业1创建的工件?

      So my question is, how can I configure job 2 to use the artifact created by job 1?

      我意识到我可以只有一个运行mvn verify的CI作业,这将只创建一次工件,但我想要有上述的单独的CI作业,以便实现Farley风格的部署管道。

      I realise I could just have one CI job that runs "mvn verify", which would create the artifact only once, but I want to have the separate CI jobs described above in order to implement a Farley-style deployment pipeline.

      如果它能帮助任何人,这是接受的答案中的项目2的完整Maven 2 POM:

      In case it helps anyone, here's the full Maven 2 POM of "project 2" in the accepted answer:

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.example.cake</groupId>
          <artifactId>cake-acceptance</artifactId>
          <version>1.0</version>
          <packaging>jar</packaging>
          <name>Cake Shop Acceptance Tests</name>
          <description>
              Runs the automated acceptance tests for the Cake Shop web application.
          </description>
          <build>
              <plugins>
                  <!-- Compiler -->
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>2.3.1</version>
                      <configuration>
                          <source>${java.version}</source>
                          <target>${java.version}</target>
                      </configuration>
                  </plugin>
                  <!-- Suppress the normal "test" phase; there's no unit tests -->
                  <plugin>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <version>2.5</version>
                      <configuration>
                          <skipTests>true</skipTests>
                      </configuration>
                  </plugin>
                  <!-- Cargo (starts and stops the web container) -->
                  <plugin>
                      <groupId>org.codehaus.cargo</groupId>
                      <artifactId>cargo-maven2-plugin</artifactId>
                      <version>1.0.5</version>
                      <executions>
                          <execution>
                              <id>start-container</id>
                              <phase>pre-integration-test</phase>
                              <goals>
                                  <goal>start</goal>
                              </goals>
                          </execution>
                          <execution>
                              <id>stop-container</id>
                              <phase>post-integration-test</phase>
                              <goals>
                                  <goal>stop</goal>
                              </goals>
                          </execution>
                      </executions>
                      <configuration>
                          <!-- Don't wait for CTRL-C after starting the container -->
                          <wait>false</wait>
      
                          <container>
                              <containerId>jetty7x</containerId>
                              <type>embedded</type>
                              <timeout>20000</timeout>
                          </container>
      
                          <configuration>
                              <properties>
                                  <cargo.servlet.port>${http.port}</cargo.servlet.port>
                              </properties>
                              <deployables>
                                  <deployable>
                                      <groupId>${project.groupId}</groupId>
                                      <artifactId>${target.artifactId}</artifactId>
                                      <type>war</type>
                                      <properties>
                                          <context>${context.path}</context>
                                      </properties>
                                  </deployable>
                              </deployables>
                          </configuration>
                      </configuration>
                  </plugin>
                  <!-- Failsafe (runs the acceptance tests) -->
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-failsafe-plugin</artifactId>
                      <version>2.6</version>
                      <executions>
                          <execution>
                              <id>integration-test</id>
                              <goals>
                                  <goal>integration-test</goal>
                              </goals>
                          </execution>
                          <execution>
                              <id>verify</id>
                              <goals>
                                  <goal>verify</goal>
                              </goals>
                          </execution>
                      </executions>
                      <configuration>
                          <includes>
                              <include>**/*Test.java</include>
                          </includes>
                          <skipTests>false</skipTests>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
          <dependencies>
                  <!-- Add your tests' dependencies here, e.g. Selenium or Sahi,
                      with "test" scope -->
              <dependency>
                  <!-- The artifact under test -->
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${target.artifactId}</artifactId>
                  <version>${target.version}</version>
                  <type>war</type>
              </dependency>
          </dependencies>
          <properties>
              <!-- The artifact under test -->
              <target.artifactId>cake</target.artifactId>
              <target.version>0.1.0-SNAPSHOT</target.version>
              <context.path>${target.artifactId}</context.path>
              <http.port>8081</http.port>
              <java.version>1.6</java.version>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
      </project>
      

      请注意,即使此测试项目不创建工件,

      Note that even though this "tests" project doesn't create an artifact, it has to use some kind of packaging (I used "jar" here), otherwise no tests are run in the verify phase.

      推荐答案

      尝试两个maven(在这里我使用jar),否则不会在验证阶段运行测试。项目。第一个包含构建和单元测试。您在本地存储库中安装工件。第二个作业运行第二个maven项目,它声明第一个项目的工件作为依赖项并运行功能测试。

      Try two maven projects. The first one contains the build and unit tests. You install the artifacts in your local repository. The second job runs the second maven project which declares the artifacts of the first project as dependencies and runs the functional tests.

      不知道我刚才描述的场景是否可能,

      Not sure if the scenario I just described is possible, but I think it is.

      为了快速改进,您可以绕过单元测试 -Dmaven.test.skip = true 。如果您将scm中的代码的修订版本号传递给第二个工作,您应该能够签出相同的源代码。

      For a quick improvement you can bypass the unit test with -Dmaven.test.skip=true. If you pass the revision number of your code in your scm to the second job, you should be able to checkout the same source code.

      您还可以检入克隆工作区SCM插件。这可能会为您提供一些其他选项。

      You can also check into the Clone Workspace SCM plugin. This might offer you some additional options.

      这篇关于如何停止Maven的验证阶段重建工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆