0

我有一个包含 cobertura 作为我的 Jenkins 运行的一部分的构建。但是,我现在意识到它正在运行我所有的测试两次。

我将项目设置为 Jenkins 中的 Maven 项目。我的目标是:clean coberture:cobertura install

我曾认为该install命令的一部分将简单地运行安装目标的其余部分,例如 package.json 。但是,它会重新运行编译和所有测试。尽管那里已经进行了测试。

我尝试配置预构建和构建后步骤的不同组合,但我一直遇到问题。在某些组合中,构建工件(例如 jars)永远不会在 Jenkins 上发布。在其他情况下,缺少测试结果。

我认为也许我需要将构建重新制作为外壳构建。我想我可以运行以下命令:mvn clean cobertura:cobertura && mvn install -Dmaven.test.skip=true

我认为这会做我想要的。它至少会停止运行所有测试两次。

这是最好的方法还是有其他方法?

这就是我在 POM 中包含 Cobertura 的方式:

  <?xml version="1.0" encoding="UTF-8"?>
  <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.foo.bar</groupId>
    <artifactId>my-parent</artifactId>
    <version>1.2.1</version>
  </parent>

  <groupId>com.foo.bar.baz</groupId>
  <artifactId>osom</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <description>TODO</description>


  <modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
  </modules>

  <dependencies>
  </dependencies>

  <build>

    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>findbugs-maven-plugin</artifactId>
          <version>3.0.3</version>
        </plugin>
      </plugins>
    </pluginManagement>


    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

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

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18</version>
        <configuration>
          <useUnlimitedThreads>true</useUnlimitedThreads>
          <parallel>suites</parallel>
          <reuseForks>false</reuseForks>
          <includes>
            <include>**/*Test.java</include>
            <include>**/Test*.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <!-- use mvn cobertura:cobertura to generate cobertura reports -->
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.7</version>
        <configuration>
          <aggregate>true</aggregate>
          <format>xml</format>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
</project>
4

2 回答 2

1

我能想到的最好方法是在 Jenkins 中使用“Freestyle”项目。

我让项目运行两个单独的 Maven 命令。mvn clean cobertura:cobertura 和 mvn install -Dmaven.test.skip=true

这可以防止测试运行两次。

于 2016-02-11T21:01:07.690 回答
1

如果您不想运行两次测试,请使用qualinsight-mojo-cobertura maven 插件而不是 cobertura-maven-plugin。

于 2016-06-18T00:08:28.877 回答