Did*_* G. 5 java jacoco jacoco-maven-plugin
基本上我只需要 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 ---
...
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ myApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 326 source files to c:\rootFolder\my_app\server\myApp\target\test-classes
...
[INFO] --- aspectj-maven-plugin:1.3:test-compile (default) @ myApp ---
...
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ myApp ---
... finally
[INFO] --- jacoco-maven-plugin:0.8.4:restore-instrumented-classes (default-restore-instrumented-classes) @ myApp ---
...
[INFO] --- jacoco-maven-plugin:0.8.4:report (default-report) @ myApp ---
[INFO] Loading execution data file c:\devel\my_app\server\MyApp\target\jacoco.exec
[INFO] Analyzed bundle 'myApp' with 5562 classes
Run Code Online (Sandbox Code Playgroud)
在“Jacoco default-instrument”中用于仅运行测试部分的任何真实示例都会很棒。这可能吗?
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<!-- any real example here? Notice maven's behavior above -->
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)
和 都jacoco:instrument与jacoco:report一起操作target/classes,因为这是要执行且测量其覆盖范围的类。
如果您放置的target/classes类多于 中的类src,则在没有相应的inclusions/的情况下exclusions,它们也将被检测和报告。
请注意,排除类并instrumentation不足以排除类report- 引用JaCoCo FAQ:
报告生成器无法区分该类是否已从检测中排除或未执行
因此,请确保您正确配置了和instrument目标report的执行。Maven 允许多种不同的方式来配置不同目标的不同执行,这里只是示例之一:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<execution>
<goals>
<goal>instrument</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects this "execution" of "instrument" and "report" goals -->
<excludes>*</excludes>
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)