当前位置: 首页 > 知识库问答 >
问题:

Tomcat7 Maven插件和JaCoCo

逄烨
2023-03-14

以下是我的POM中的一些相关片段:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.6.2.201302030002</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.14</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <systemProperties>
            <!-- as expected, this system property doesn't work since Tomcat is embedded, but this is the type of config I'm looking for -->
            <JAVA_OPTS>-javaagent:${project.build.directory}/${jacoco.jar}=destfile=${project.build.directory}/jacoco.exec,append=true</JAVA_OPTS>
        </systemProperties>
    </configuration>
    <executions>
        <execution>
            <id>tomcat-startup</id>
            <goals>
                <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <fork>true</fork>
            </configuration>
        </execution>
        <execution>
            <id>tomcat-shutdown</id>
            <goals>
                <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>

版本:Maven 3.0.4、Tomcat Maven Plugin2.1、Jacoco 0.6.2.201302030002、Java7

共有1个答案

闻人越
2023-03-14

我知道自从这个问题发布以来已经有一段时间了,但我觉得答案并没有真正解决问题的根源。如果您在这些插件中运行测试,代码覆盖率可能与failsafe或surefire一起工作。但是,如果您只是想用jacoco监视tomcat,以获得覆盖率报告,那么当前的信息并不能提供这一点。我发现tomcat7-maven-plugin不允许您通过简单地提供java_opts来为jacoco注入-javaagent。切换到货物,我能够这样做。

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.2.201409121644</version>
    <configuration>
        <destFile>${sonar.jacoco.reportPath}</destFile>
        <dataFile>${sonar.jacoco.reportPath}</dataFile>
        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
        <classDumpDir>${project.reporting.outputDirectory}/jacoco-it/classes</classDumpDir>
        <skip>${skipITs}</skip>
    </configuration>
    <executions>
        <execution>
            <id>jacoco-agent</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>${sonar.jacoco.reportPath}</destFile>
                <propertyName>jacoco.agent.itArgLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-report</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>dump</goal>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>
    <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.4.11</version>
    <configuration>
        <skip>${skipITs}</skip>
        <container>
            <containerId>tomcat7x</containerId>
            <zipUrlInstaller>
                <url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip
                </url>
                <downloadDir>${project.build.directory}/downloads</downloadDir>
                <extractDir>${project.build.directory}/extracts</extractDir>
            </zipUrlInstaller>
            <dependencies>
                <dependency>
                    <groupId>ojdbc</groupId>
                    <artifactId>ojdbc6</artifactId>
                </dependency>
            </dependencies>
        </container>
        <configuration>
            <home>${project.build.directory}/catalina-base</home>
            <properties>
                <cargo.jvmargs>${jacoco.agent.itArgLine},output=tcpserver,port=6300 -Drunmode=TEST</cargo.jvmargs>
                <cargo.servlet.port>9090</cargo.servlet.port>
            </properties>
            <configfiles>
                <configfile>
                    <file>${basedir}/src/test/conf/context.xml</file>
                    <todir>conf/Catalina/localhost/</todir>
                    <tofile>context.xml.default</tofile>
                </configfile>
            </configfiles>
        </configuration>
    </configuration>
    <executions>
        <execution>
            <id>start-tomcat</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-tomcat</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

重要的部分是:

  1. org.jacoco ... jacoco.agent.itargline
  2. ${jacoco.agent.itargline},output=tcpserver,port=6300
 类似资料:
  • 问题内容: 因此,我正在AngularJS中创建一个新站点,并且对此非常喜欢! 但是,我遇到了一个问题。我试图在我的textareas中添加一个名为“ Redactor”的jQuery插件,但是我认为正在发生的事情是,当我初始化该插件时,它将替换textarea元素。之所以有问题,是因为我为文本区域设置了“ ng-model”属性,如下所示: 我正在使用AngularJS UI拾取焦点事件,然后在

  • 新的Maven项目是在eclipse中创建的。但是Pom.xml显示了一些错误。 “无法计算构建计划:Plugin org.apache.maven。插件:maven resources插件:2.6或其一个依赖项无法解析:未能读取org.apache.maven的工件描述符。插件:maven resources插件:jar:2.6 Plugin org.apache.maven。插件:maven

  • 下载、安装国内期货交易插件 OpenQuant系统中可以由第三方服务商或者开发者自行进行扩展,例如行情源的接入、交易通道的接入、历史数据源的接入等等,这些扩展我们称之为插件(Plugins)。 上期技术公司的CTP系统是获取国内期货实时行情、进行交易的主要平台。各个主流期货经纪商均支持客户通过CTP柜台进行期货、期权的交易。您可以在SmartQuant中文网站(http://www.smartqu

  • 问题内容: 在下面的Jenkins作业配置中, Refspec 和 Branch specifier(默认为空白) 之间有什么区别: 我试图在作业配置中设置Refspec选项: 在我的构建从属服务器上的克隆仓库中,.git / config文件如下所示: 似乎 fetch 的值不正确(从jenkins作业配置中读取)。此外,它对磁盘空间消耗没有影响。 问题答案: Refspec 定义了 获取 操作

  • 我们有一个使用分级构建工具的java项目。我们正在使用jaco插件来生成测试覆盖率报告。后来,我们使用 gradle 的 JVM 测试套件插件添加了测试套件。我们已经观察到,所有由测试套件运行的测试类都没有在jacoco的代码覆盖率报告中涵盖。因此,如果有人知道我应该在build.gradle文件中写什么来完成这项工作,那就太好了。谢谢。 这是build.gradle文件片段:-

  • 有办法让这成为可能吗? 感谢您的关注!