小编Did*_* G.的帖子

如何从 jacoco 报告中正确排除和包含类、包和 jar 类、lib(离线仪器)

我正在使用 JaCoCo 代码覆盖率,但报告包括来自 jar、lib 的类。(离线检测,Maven)

我解决了离线配置的问题,因为“aspectj-maven-plugin”正在更改类文件,现在我也成功地排除了target/classes->之外的包src。感谢stackoverflow 中的这个答案。但是现在我从报告中的 jar、lib 获取类,我不知道如何排除。我在下面显示我的配置和示例

我也试过这个解决方案Exclude classes of jar files from jacoco coverage report但它对我不起作用。 <exclude>**/lib/*</exclude>

我的jacoco离线配置:

<properties>
  <jacoco.version>0.8.4</jacoco.version>
  <argLine></argLine>
</properties>


<dependency>
  <groupId>org.jacoco</groupId>
  <artifactId>org.jacoco.agent</artifactId>
  <classifier>runtime</classifier>
  <version>${jacoco.version}</version>
</dependency>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                    <goals>
                        <goal>instrument</goal>
                        <goal>restore-instrumented-classes</goal>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- this configuration affects all goals -->
                        <excludes>
                            <exclude>*</exclude>
                            <exclude>com/company/rrPackage/**/*.class</exclude>
                            <exclude>org/**/*.class</exclude>                                               
                        </excludes>
                    </configuration>
                    </execution>
                </executions>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

万无一失的插件

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <testNGArtifactName>...</testNGArtifactName>
                    <suiteXmlFiles>
                        <suiteXmlFile>...</suiteXmlFile>
                    </suiteXmlFiles>
                    <skip>${skip.test}</skip>
                    <systemPropertyVariables>
                        <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>                       
                    </systemPropertyVariables> …
Run Code Online (Sandbox Code Playgroud)

java maven jacoco jacoco-maven-plugin

8
推荐指数
1
解决办法
2420
查看次数

&lt;goal&gt;instrument&lt;/goal&gt; 中的 JaCoCo (Offline Instrumentation) 分析整个 pom.xml。但我只需要测试部分

基本上我只需要 jacoco 检测测试部分,但是检测整个 pom.xml,并且报告随附了所有内容(来自“oracle.jdbc.driver”、“com.mysql.jdbc”...等的数据)

我已经尝试了几天几乎所有的东西。但到目前为止我还没有成功

注意这里jacoco:instrument如何检测整个 pom.xml

[INFO] --- jacoco-maven-plugin:0.8.4:instrument (default-instrument) @ myApp ---
...
[DEBUG]   (f) project = MavenProject: com.firstPackage.tdz:myApp:X.1.0 @ C:\rootFolder\my_app\server\MyApp\pom.xml
Run Code Online (Sandbox Code Playgroud)

我的测试运行

[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ myApp ---
[DEBUG] Source directories: [C:\rootFolder\my_app\server\myApp\tests\src]
[DEBUG] Classpath: [C:\devel\my_app\server\myApp\target\test-classes
Run Code Online (Sandbox Code Playgroud)

这是我的 Maven 流程:

[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ myApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3582 source files to c:\rootFolder\my_app\server\myApp\target\classes
...
[INFO] --- aspectj-maven-plugin:1.3:compile (default) @ myApp ---
...
[INFO] --- jacoco-maven-plugin:0.8.4:instrument (default-instrument) @ myApp --- …
Run Code Online (Sandbox Code Playgroud)

java jacoco jacoco-maven-plugin

5
推荐指数
1
解决办法
617
查看次数

标签 统计

jacoco ×2

jacoco-maven-plugin ×2

java ×2

maven ×1