【问题标题】:Jacoco's report not generateJacoco 的报告未生成
【发布时间】:2022-06-13 17:50:56
【问题描述】:

在我的 pom.xml 中

    <profile>
            <id>coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-Xmx4096m ${jacoco.agent.ut.arg}</argLine>
<!--                            Specific to generate mapping between tests and covered code -->
                            <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.sonar.java.jacoco.JUnitListener</value>
                                </property>
                            </properties>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <argLine>-Xmx4096m ${jacoco.agent.it.arg}</argLine>
<!--                            Specific to generate mapping between tests and covered code -->
                            <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.sonar.java.jacoco.JUnitListener</value>
                                </property>
                            </properties>
<!--                            Let's put failsafe reports with surefire to have access to tests failures/success reports in sonar -->
                            <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.4.201502262128</version>
                        <executions>
<!--                            Prepares a variable, jacoco.agent.ut.arg, that contains the info to be passed to the JVM hosting the code being tested. -->
                            <execution>
                                <id>prepare-ut-agent</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-ut.exec</destFile>
                                    <propertyName>jacoco.agent.ut.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
<!--                            Prepares a variable, jacoco.agent.it.arg, that contains the info to be passed to the JVM hosting the code being tested. -->
                            <execution>
                                <id>prepare-it-agent</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                                    <propertyName>jacoco.agent.it.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.sonar-plugins.java</groupId>
                    <artifactId>sonar-jacoco-listeners</artifactId>
                    <version>1.5</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
    

运行

mvn clean verify

但target文件夹中不存在jacoco的报道报告

【问题讨论】:

    标签: maven jacoco


    【解决方案1】:

    由于您的配置文件默认未激活,因此您需要在 maven 命令中指定-Pcoverage 才能运行此配置文件。

    mvn clean verify -Pcoverage
    

    您还可以通过将以下内容添加到您的 pom.xml 来激活您的 coverage 个人资料

    <profile>
       <id>coverage</id>
       <activation>
          <activeByDefault>true</activeByDefault>
       </activation>
       <!-- Rest of the Profile build configuration -->
    </profile>
    

    【讨论】:

      猜你喜欢
      • 2015-07-19
      • 2014-05-15
      • 2018-12-18
      • 2018-09-09
      • 1970-01-01
      • 2022-06-15
      • 2019-09-07
      • 1970-01-01
      • 2015-01-18
      相关资源
      最近更新 更多