cobertura-maven-plugin 找不到我的 groovy 源代码
cobertura-maven-plugin cannot find my groovy source code
我正在尝试使用 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 在哪里可以找到我的 groovy 源,但我找不到示例。
Cobertura Maven 插件不提供自定义源位置的方法。默认情况下,它会查看 Maven 标准文件夹,即 src/main/java
。由于您的 Groovy 类 位于 src/main/groovy
内,因此未找到它们。
根据您的项目,有 2 种解决方案:
在 build-helper-maven-plugin:add-source
Mojo 的帮助下将这些源添加到项目中:
<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 特定文件夹。
用
覆盖 Maven 的 the source directory
<build>
<sourceDirectory>src/main/groovy</sourceDirectory>
<!-- rest of build configuration -->
</build>
如果项目是纯 Groovy 项目,没有任何源 Java 文件,这将很方便。
通过这两项更改中的任何一项,运行 mvn clean site
将生成一份 Cobertura 报告,其中将正确找到 Groovy 来源。
我正在尝试使用 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 在哪里可以找到我的 groovy 源,但我找不到示例。
Cobertura Maven 插件不提供自定义源位置的方法。默认情况下,它会查看 Maven 标准文件夹,即 src/main/java
。由于您的 Groovy 类 位于 src/main/groovy
内,因此未找到它们。
根据您的项目,有 2 种解决方案:
在
build-helper-maven-plugin:add-source
Mojo 的帮助下将这些源添加到项目中:<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 特定文件夹。
用
覆盖 Maven 的 the source directory<build> <sourceDirectory>src/main/groovy</sourceDirectory> <!-- rest of build configuration --> </build>
如果项目是纯 Groovy 项目,没有任何源 Java 文件,这将很方便。
通过这两项更改中的任何一项,运行 mvn clean site
将生成一份 Cobertura 报告,其中将正确找到 Groovy 来源。