Maven 在构建期间没有运行 Jacoco
Posted
技术标签:
【中文标题】Maven 在构建期间没有运行 Jacoco【英文标题】:Maven not running Jacoco during build 【发布时间】:2017-08-31 08:31:44 【问题描述】:我正在尝试使用 Jacoco 进行代码覆盖,但每次运行时
mvn 全新安装
我在输出日志中收到以下消息:
--- jacoco-maven-plugin:0.7.9:report (post-unit-test) @myDemo --- 由于缺少执行数据文件而跳过 JaCoCo 执行。
我尝试了此处找到的解决方案:Getting "Skipping JaCoCo execution due to missing execution data file" upon executing JaCoCo? 但是添加 @argLine 似乎没有帮助。
这是我的 pom.xml 文件,任何见解都将不胜感激。谢谢!
<?xml version="1.0" encoding="UTF-8"?>
<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.mine</groupId>
<artifactId>myDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myDemo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>org.mine.mydemo.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Virginia Tech Applied Research</name>
</organization>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.css</include>
<include>**/*.csv</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/images</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/styles</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>$project.build.directory/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>$java.home/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>$mainClass</argument>
<argument>-srcdir</argument>
<argument>$project.build.directory/classes</argument>
<argument>-outdir</argument>
<argument>$project.build.directory</argument>
<argument>-outfile</argument>
<argument>$project.build.finalName.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>$java.home/bin/java</executable>
<commandlineArgs>$runfx.args</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>$sun.boot.class.path$path.separator$java.home/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>$java.home/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
<argLine>@argLine</argLine>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>sax</groupId>
<artifactId>sax</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>javafx-d3</groupId>
<artifactId>javafx-d3</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.12</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
【问题讨论】:
【参考方案1】:尝试在 pom.xml 中的 maven jacoco plugin
中添加以下行。
<configuration>
<destFile>$basedir/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>$basedir/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
您注意到这里,我正在向 jacoco 提供数据文件位置。
【讨论】:
我只是尝试在插件的版本元素之后直接添加这个配置元素。我收到了和以前一样的日志消息。以上是关于Maven 在构建期间没有运行 Jacoco的主要内容,如果未能解决你的问题,请参考以下文章
Ant 在 JDK9 上的 maven 构建期间无法创建 .pkg 文件