maven构建中的代码覆盖 - 由于缺少类目录而跳过JaCoCo执行 [英] Code coverage in maven build - Skipping JaCoCo execution due to missing classes directory

查看:208
本文介绍了maven构建中的代码覆盖 - 由于缺少类目录而跳过JaCoCo执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个项目但是现在我有一个多模块项目,我能够使代码覆盖正常工作。

I am able to get code coverage working fine if I have a single project but now I have a multi module project.

我的应用程序是在api项目中构建的并且我的所有集成测试都在一个单独的项目中运行,该项目使用前面模块构建的artefact。

My application is built in the api project and all my integration tests are running in a separate project which uses the artefact built as previous module.

构建运行但我没有得到代码覆盖率报告,而是我得到信息消息:

The build runs but I dont get a code coverage report, instead I get the info message:

由于缺少班级目录而跳过JaCoCo执行

Skipping JaCoCo execution due to missing classes directory

我的报道文件jacoco-it。 exec已经创建,但似乎jacoco插件需要项目中运行测试的类。

My coverage report file jacoco-it.exec is created but it seems like the jacoco plugin requires the classes in the project the tests are running in.

有人可以告诉我我需要做什么才能够当这些类在另一个模块中时创建一个覆盖率报告?

Can somebody tell me what I need to do to be able to create a coverage report when the classes are in another module?

推荐答案

我已经设法通过试用获得各种解决方法错误。

I have managed to get a workaround of sorts going through trial and error.

似乎jacoco插件很乐意创建没有类的exec文件但是我没有它们就不会创建报告,我不明白jacoco是如何在内部工作所以如果有人知道你能解释一下吗?

It seems the jacoco plugin is happy to create the exec file without the classes but it will not create the report without them, I dont understand how jacoco is working internally so if someone knows could you please explain it?

我也不确定我是不是已经完成的是可靠的,但它似乎确实报告了我的硒驱动测试的覆盖范围。

I am also not sure if what I have done is reliable but it does seem to report the coverage of my selenium driven tests.

我自己想出的我的(可能的)解决方案是使用maven资源插件将已经从target \ cargo ..目录中的war文件展开的类复制到目录target\classes:

My (possible) solution which I have come up with myself is to use the maven resources plugin to copy the classes which have been exploded from the war file in my target\cargo.. directory into the directory target\classes:

 <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>copy-resources</id>             
            <phase>pre-integration-test</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/classes</outputDirectory>
              <resources>          
                <resource>
                  <directory>${basedir}/target/cargo/configurations/tomcat7x/webapps/calculator-api/WEB-INF/classes</directory>
                  <filtering>false</filtering>
                  <excludes>
                        <exclude>**/*Config*.*</exclude>
                        <exclude>**/*Initialiser*.*</exclude>
                  </excludes>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
    </plugin>

这似乎让jacoco插件很开心,我得到了我的代码覆盖率,虽然看起来插件忽略了我的排除列表现在。

This seems to keep the jacoco plugin happy and I get my code coverage, although it seems the plugin ignores my exclude list now.

有人知道这是否真的是一个解决方案,它似乎'工作'但我无法在网上找到这是推荐的方法,我我也不确定为什么jacoco代理设置的排除选项似乎不再起作用。

Does anybody know if this is actually a solution, it 'seems' to work but I cant find anywhere online where this is a recommended approach and I am also unsure of why the exclude option on the jacoco agent set up no longer seems to work.

我设法绕过jacoco插件而不是排除文件使用资源插件复制它们但我仍然不清楚jacoco是如何工作的。

I have managed to get around the jacoco plugin not excluding files by just not copying them with the resources plugin but I still dont understand exactly how jacoco is working.

这篇关于maven构建中的代码覆盖 - 由于缺少类目录而跳过JaCoCo执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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