Maven在构建期间没有运行Jacoco

时间:2017-04-05 15:53:44

标签: java maven pom.xml jacoco

我尝试使用Jacoco进行代码覆盖,但每次运行

  

mvn clean install

我在输出日志中收到以下消息:

  

--- jacoco-maven-plugin:0.7.9:报告(单元后测试)@ 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 个答案:

答案 0 :(得分:0)

尝试在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提供数据文件位置。