1

我有一个带有 java 和 scala 的多模块项目。jacoco 和 scoverage 插件都安装在 Jenkins 中,我想在 Jenkins 的单个构建作业中生成 jacoco 和 scoverage 报告(两者),但只生成一个报告,要么是 jacoco,要么是 scoverage。

到目前为止尝试过的 mvn 命令下面 -

mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install scoverage:report jacoco:report

mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install jacoco:report scoverage:report

我的 pom 文件的片段 -

Plugins section -
<plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.9</version>
        <configuration>
            <destFile>./target/jacoco.exec</destFile>
            <append>true</append>
        </configuration>
        <executions>
            <execution>
                <id>default-prepare-agent</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>default-report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.scoverage</groupId>
        <artifactId>scoverage-maven-plugin</artifactId>
        <version>1.3.0</version>
        <configuration>
            <scalaVersion>2.10.4</scalaVersion>
            <highlighting>true</highlighting>
            <aggregate>true</aggregate>
        </configuration>
    </plugin>
</plugins>

Reporting section - 
<reporting>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.scoverage</groupId>
            <artifactId>scoverage-maven-plugin</artifactId>
            <version>1.3.0</version>
            <configuration>
                <aggregate>true</aggregate>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
        </plugins>
    </reporting>

当我使用 - mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install scoverage:report jacoco:report

生成 jacoco 报告

构建日志 -

05:30:51 [编译] [INFO] --- scoverage-maven-plugin:1.3.0:report (default-cli) @ ABC --- 05:30:51 [编译] [INFO] 读取 scoverage 工具 [ /workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.coverage.xml]... 05:30:51 [编译] [INFO] 读取覆盖测量值 [/workspace/Build-Pipeline/ABC/target/ scoverage-data/scoverage.measurements.*]... 05:30:51 [编译] [INFO] 生成覆盖率报告... 05:30:51 [编译] [INFO] 书面 Cobertura XML 报告 [/workspace/Build -Pipeline/ABC/target/cobertura.xml] 05:30:52 [编译] [INFO] 书面 XML 覆盖率报告 [/workspace/Build-Pipeline/ABC/target/scoverage.xml] 05:30:53 [编译] [INFO] 书面 HTML 覆盖率报告 [/workspace/Build-Pipeline/ABC/target/site/scoverage/index.html] 05:30:53 [编译] [INFO] 语句覆盖率。:0.00% 05:30:53 [编译] [INFO] 分支覆盖率....:0.00% 05:30:53 [编译] [INFO] 覆盖率报告已完成。

当我使用 -

mvn -B -s $MVN_SETTINGS jacoco:prepare-agent install jacoco:report scoverage:report

生成覆盖率报告

构建日志 -

05:15:07 [编译] [INFO] --- scoverage-maven-plugin:1.3.0:report (default-cli) @ ABC --- 05:15:07 [编译] [INFO] 读取 scoverage 工具 [ /workspace/Build-Pipeline/ABC/target/scoverage-data/scoverage.coverage.xml]... 05:15:07 [编译] [INFO] 读取覆盖测量值 [/workspace/Build-Pipeline/ABC/target/ scoverage-data/scoverage.measurements.*]... 05:15:07 [编译] [INFO] 生成覆盖率报告... 05:15:07 [编译] [INFO] 书面 Cobertura XML 报告 [/workspace/Build -Pipeline/ABC/target/cobertura.xml] 05:15:08 [编译] [INFO] 书面 XML 覆盖率报告 [/workspace/Build-Pipeline/ABC/target/scoverage.xml] 05:15:08 [编译] [INFO] 书面 HTML 覆盖率报告 [/workspace/Build-Pipeline/ABC/target/site/scoverage/index.html] 05:15:08 [编译] [INFO] 语句覆盖率。:0.00% 05:15:08 [编译] [INFO] 分支覆盖率....:0.00% 05:15:08 [编译] [INFO] 覆盖率报告已完成。

有人可以指出我出了什么问题吗?

非常感谢

4

1 回答 1

2

给定src/main/java/HelloJava.java

class HelloJava {
  public static String msg() {
    return "Hello";
  }
}

src/main/scala/HelloScala.scala

object HelloScala {
  def msg = {
    "Hello"
  }
}

src/test/java/HelloTest.java

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class HelloTest {
  @Test
  public void test() {
    assertEquals("Hello", HelloJava.msg());
    assertEquals("Hello", HelloScala.msg());
  }
}

pom.xml

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

  <groupId>org.example</groupId>
  <artifactId>example</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.11.6</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/main/scala</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-test-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/test/scala</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.4.4</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.2</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.scoverage</groupId>
        <artifactId>scoverage-maven-plugin</artifactId>
        <version>1.1.1</version>
        <configuration>
          <highlighting>true</highlighting>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

执行mvn clean test jacoco:report scoverage:report

会产生target/site/jacoco/index.html

雅可可报告

target/site/scoverage/index.html

覆盖报告

于 2019-01-15T16:18:35.270 回答