在跳过JaCoCo执行之前,JaCoCo不会生成jacoco.exec [英] JaCoCo not generating jacoco.exec until after skipping JaCoCo execution

查看:203
本文介绍了在跳过JaCoCo执行之前,JaCoCo不会生成jacoco.exec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个模块中无法通过JaCoCo生成AHP报告.当构建开始时,我看到JaCoCo使用以下命令正确设置了argLine:

I'm having trouble generating AHP reports via JaCoCo in one of my modules. When the build starts, I see JaCoCo correctly setting argLine with:

[INFO] jacoco.agent.argLine set to -javaagent:<...>/.m2/repository/org/jacoco/org.jacoco.agent/0.7.2.201409121644/org.jacoco.agent-0.7.2.201409121644-runtime.jar=destfile=<...>/target/jacoco.exec

但是,当maven尝试运行JaCoCo时,尚未创建.exec:

However, the .exec hasn't been created yet by the time maven tries to run JaCoCo:

[INFO] Skipping JaCoCo execution due to missing execution data file:<...>/target/jacoco.exec

在maven跳过JaCoCo执行之后,jacoco.exec最终被创建了.因此,如果我重新运行构建而不进行清理,我仍然可以生成AHP报告.

The jacoco.exec does eventually get created, after maven has skipped JaCoCo execution. Therefore, I can still generate AHP reports, if I re-run the build without cleaning.

在其他各种问题中,我还需要谨慎地将Maven Surefire与JaCoCo一起使用.但是,我没有在我的Surefire插件或任何插件中明确使用argLine.我开始怀疑其他插件之一是否像JaCoCo一样自动劫持argLine参数.

I've seen in various other questions that I need to be careful using Maven Surefire with JaCoCo. However, I don't explicitly use argLine in my Surefire plugins, or in any plugin for that matter. I'm starting to wonder if one of the other plugins is hijacking the argLine parameter automatically like JaCoCo does.

以下是所有使用的插件的列表:

Here is a list of all plugins used:

  • jacoco-maven-plugin
  • vertx-maven-plugin
  • maven-resources-plugin
  • maven-dependency-plugin
  • maven-surefire-plugin
  • maven-failsafe-plugin
  • maven-surefire-report-plugin
  • maven-assembly-plugin

我在构建输出中确实看到一条可疑消息:

I do see one suspicious message in the build output:

[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ <module> ---
[INFO] Changes detected - recompiling the module!

我不确定这是否有意义,但是它会在跳过"消息之前出现两次,并且不会出现在JaCoCo正常工作的模块中.

I'm not sure if that's relevant, but it appears twice before the Skipping message, and doesn't appear in a module where JaCoCo works properly.

有什么想法吗?

* edit-这是jacoco的配置

*edit - Here's the jacoco config

    <plugins>
        <...>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.jacoco</groupId>
                                    <artifactId>
                                        jacoco-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [0.7.2.201409121644,)
                                    </versionRange>
                                    <goals>
                                        <goal>prepare-agent</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

我不确定插件管理部分到底在做什么,但是将其注释掉并不能解决任何问题.我还尝试过将JaCoCo插件配置放在surefire/failsafe配置之上,以防万一对于具有相同目标的插件来说顺序很重要,但这也无济于事.

I'm not sure exactly what that plugin management part is doing, but commenting it out doesn't fix anything. I've also tried putting the JaCoCo plugin config above the surefire/failsafe config in case order mattered for plugins sharing the same goals, but that didn't help either.

* edit 2-看起来问题出在surefire的内容中.注释掉它们会以某种方式修复JaCoCo的.exec代,并且JaCoCo可以正常工作.

*edit 2 - Looks like the problem was surefire's includes. Commenting them out somehow fixes JaCoCo's .exec generation, and JaCoCo works properly.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin.version}</version>
            <configuration>
                <!-- <includes>
                    <include>**/unit/**/*Test*.java</include>
                </includes> -->
            </configuration>
        </plugin>

有人知道为什么吗?

推荐答案

只是已经给出的答案的补充. 可能发生的是,在您的maven-surefire-plugin配置中,您已经使用argLine配置来覆盖诸如所使用的内存之类的东西.如果这样做,则无法使用由jacoco-maven-plugin设置的argline而不生成jacoco报告. 在这种情况下,请为jacoco-maven-plugin配置分配一个属性名称,然后在您的maven-surefire-plugin argLine参数中引用它.

Just an addition to the answers already given. It could happen that in your maven-surefire-plugin configuration you already use the argLine configuration to override something like the memory used. If you do so the argline set by jacoco-maven-plugin will not be used failing to generate the jacoco report. In this case assign a property name to the jacoco-maven-plugin config and then reference it in your maven-surefire-plugin argLine parameter.

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <executions>
                <!-- prepare agent for measuring unit tests -->
                <execution>
                    <id>prepare-unit-tests</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <append>true</append>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                        <!-- Sets the VM argument line used when unit tests are run. -->
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
            </executions>
        </plugin>

[...]

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <printSummary>false</printSummary>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <forkCount>3</forkCount>
                <reuseForks>true</reuseForks>
                <argLine>${surefireArgLine} -Xmx1024m -noverify</argLine>                  
            </configuration>
        </plugin>

这篇关于在跳过JaCoCo执行之前,JaCoCo不会生成jacoco.exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆