JaCoCo:缺少类目录 [英] JaCoCo: missing classes directory

查看:86
本文介绍了JaCoCo:缺少类目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JaCoCo还是陌生的,并且在生成代码覆盖率报告时遇到了麻烦.

I am fairly new to JaCoCo and I am having trouble generating my code coverage report.

这是我的项目结构:

我的集成测试存在于"...- integration-tests"模块中.当我使用mvn构建项目时,在日志记录中会得到以下内容:

My integration tests live within the "...-integration-tests" module. When I build my project using mvn I get the following in my logging:

[INFO] Skipping JaCoCo execution due to missing classes directory: ...-integration-tests\target\classes

这是正确的,因为我的编译后的代码仅在相应模块的target>类中可用.

This is true because my compiled code is only available in the target>classes of the corresponding module.

使此工作最佳的方法是什么?预先感谢!

What is the best way to make this working? Thanks in advance!

推荐答案

发生这种情况是因为JaCoCo报告" mojo试图在默认" maven项目布局中查找源和类:

This happens because JaCoCo "report" mojo is trying to find sources and classes in "default" maven project layout:

@Override
boolean canGenerateReportRegardingClassesDirectory() {
    return new File(getProject().getBuild().getOutputDirectory()).exists();
}

具有与您相似的布局,我可以通过显式设置 build.sourceDirectory build.outputDirectory 指向您已测试模块的内部,从而规避JaCoCo配置限制.在那个maven尝试第二次编译它之后,所以我还不得不覆盖默认的编译执行,我的Tests模块pom.xml的重要(可共享)部分现在看起来像这样:

Having layout similar to yours I was able to circumvent JaCoCo configuration limitations by explicitly setting build.sourceDirectory and build.outputDirectory to point on internals of your tested module. After that maven tried to compile it for second time, so I've also had to override default compile execution, important (and shareable) part of my Tests module pom.xml now look like this:

<?xml version="1.0" encoding="UTF-8"?>
<project ...
...
    <parent>
...
    </parent>

    <dependencies>
...
    </dependencies>

    <properties>
...
    </properties>

    <build>
        <sourceDirectory>../../Source</sourceDirectory> <!-- tested sources root, in proper layout: src/main/java -->
        <outputDirectory>../bin</outputDirectory> <!-- tested classes root, in proper layout: target/classes -->

        <testSourceDirectory>${project.basedir}/../../Test/java</testSourceDirectory> <!-- if tests code also taken from outside -->

        <testResources>
            ...
        </testResources>

        <plugins>
...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <executions>
                    <!-- disabling default-compile -->
                    <execution>
                        <id>default-compile</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <phase>compile</phase>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                            <includes/>
                            <excludes>
                                <exclude>**/*.java</exclude>
                            </excludes>
                        </configuration>
                    </execution>
...
                </executions>
            </plugin>

            <!-- typical jacoco usage -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <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>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit4</artifactId>
                        <version>2.10</version>
                    </dependency>
                </dependencies>
                <configuration>
...
                    <argLine>${argLine} -XX:PermSize=512M -XX:MaxPermSize=512M -Xmx1024M</argLine>
...
                    <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks>
                </configuration>
                <executions>
...
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这篇关于JaCoCo:缺少类目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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