我正在尝试使用 apache-aven 为我的 Java/Groovy 项目生成代码覆盖率报告。附件是pom文件:
<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>com.hal_con</groupId>
<artifactId>scheduler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<configuration>
<providerSelection>1.8</providerSelection>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/cobertura-maven-plugin -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</reporting>
</project>
我尝试了以下两种方法:
按照以下建议添加 maven-source-plugin:Maven + Cobertura : Unable to locate [Your Class]. Have you specified the source directory?
按照以下建议添加 jxr-maven-plugin: maven-cobertura-plugion does not show the sources
两种情况的结果完全相同:
Unable to locate com/hal_con/scheduler/FileParser.groovy. Have you specified the source directory?
我认为需要告诉 maven-cobertura-plugin 在哪里可以找到我的常规源,但我找不到示例。
最佳答案
Cobertura Maven 插件不提供自定义源位置的方法。默认情况下,它会查找 Maven 标准文件夹,即 src/main/java 。由于您的 Groovy 类位于 src/main/groovy 内部,因此找不到它们。
根据您的项目,有 2 种解决方案:
借助
build-helper-maven-plugin:add-source
将这些源添加到项目中魔力:<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> </executions> </plugin>
如果项目是混合 Java/Groovy 项目,这会很有帮助,因为您可以保留 Maven 默认值,并添加 Groovy 特定文件夹。
覆盖the source directory Maven 与
<build> <sourceDirectory>src/main/groovy</sourceDirectory> <!-- rest of build configuration --> </build>
如果项目是纯 Groovy 项目,没有任何 Java 源文件,这会很方便。
通过这两项更改中的任何一个,运行 mvn clean site
将生成一个 Cobertura 报告,其中将正确找到 Groovy 源代码。
关于maven - cobertura-maven-plugin 找不到我的 groovy 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42192224/