gpt4 book ai didi

java - 我在 Apache Tika 的 POM 文件中添加 Jacoco Maven 插件来获取代码覆盖率。但我这样做遇到了问题

转载 作者:行者123 更新时间:2023-12-02 04:38:32 27 4
gpt4 key购买 nike

Apache Tika 项目有一个根目录,其中存在 pom.xml。根目录内有名为“Tika-Parent”的子模块和模块。父模块内部还有一个 pom.xml 文件。

现在我正在向 Tika 添加 jacoco Maven 插件以获取代码覆盖率,但我遇到了问题,因为当我将 Jacoco Maven 插件添加到根目录中的 Pom.xml 时。它构建成功,但给出错误:“由于缺少执行数据文件而跳过 JaCoCo 执行:C:\Users\adity\IdeaProjects\tika-1.20\target\jacoco.exec”

我尝试将 JaCOCO 插件一起添加到两个 pom.xml 文件中,也尝试将它们一一添加,但没有结果。

此外,当我对根目录中的 pom.xml 执行 Maven 测试时,它会成功构建并运行所有测试。

但是当我在 Tika-parent 的 pom.xml 上执行 Maven 测试时,它不会运行任何测试,但会成功构建。

我将根目录中的 Pom.xml 以及根目录中 Tika-parent 模块的 pom.xml 附加到下面。

我正在使用 IntelliJ Community 版本(网站上的最新版本)。Java版本-JDK 8,Maven 版本 3。

这些详细信息来自根目录 pom.xml

<modules>
<module>tika-parent</module>
<module>tika-core</module>
<module>tika-parsers</module>
<module>tika-bundle</module>
<module>tika-xmp</module>
<module>tika-serialization</module>
<module>tika-batch</module>
<module>tika-app</module>
<module>tika-server</module>
<module>tika-translate</module>
<module>tika-langdetect</module>
<module>tika-example</module>
<module>tika-java7</module>
<module>tika-eval</module>
<module>tika-dl</module>
<module>tika-nlp</module>
</modules>

这些是属性

<jacoco.version>0.7.5.201505241946</jacoco.version>
<junit.version>4.12</junit.version>
<junit.platform.version>1.3.1</junit.platform.version>

<maven.antrun.version>1.8</maven.antrun.version>
<maven.assembly.version>3.1.0</maven.assembly.version>
<maven.bundle.version>4.0.0</maven.bundle.version>
<maven.failsafe.version>2.22.1</maven.failsafe.version>
<maven.javadoc.version>3.0.1</maven.javadoc.version>
<maven.scr.version>1.7.4</maven.scr.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
<maven.shade.version>3.2.0</maven.shade.version>
<rat.version>0.12</rat.version>

这些是依赖项

<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>

</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
<scope>test</scope>

</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>



<dependency>

<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>0.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

下面是Build.Plugins中的所有插件。

这是 JACOCO 插件

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

这是 Surefire 插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<reuseForks>false</reuseForks>
<forkCount>1</forkCount>
</configuration>
</plugin>

这是 apache Rat 插件

<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>${rat.version}</version>
<configuration>
<excludes>
<exclude>CHANGES.txt</exclude>
</excludes>
</configuration>
</plugin>

其余的pom.xml中没有其他插件

下面是根目录中 Iika-Parent 模块的 pom.xml。

这些是属性。

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.build.sourceEncoding}
</project.reporting.outputEncoding>


<!-- plugin versions -->
<jacoco.version>0.7.5.201505241946</jacoco.version>
<junit.version>4.12</junit.version>
<junit.platform.version>1.3.1</junit.platform.version>



<forbiddenapis.version>2.6</forbiddenapis.version>
<groovy.maven.version>2.0</groovy.maven.version>
<maven.antrun.version>1.8</maven.antrun.version>
<maven.assembly.version>3.1.0</maven.assembly.version>
<maven.bundle.version>4.0.0</maven.bundle.version>
<maven.failsafe.version>2.22.1</maven.failsafe.version>
<maven.javadoc.version>3.0.1</maven.javadoc.version>
<maven.scr.version>1.7.4</maven.scr.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
<maven.shade.version>3.2.0</maven.shade.version>
<rat.version>0.12</rat.version>


<!-- NOTE: sync tukaani version with commons-compress in tika-parsers -->


<poi.version>4.0.1</poi.version>
<commons.compress.version>1.18</commons.compress.version>
<commons.io.version>2.6</commons.io.version>
<commons.lang3.version>3.8.1</commons.lang3.version>
<gson.version>2.8.5</gson.version>
<osgi.core.version>6.0.0</osgi.core.version>

<cxf.version>3.2.7</cxf.version>
<slf4j.version>1.7.25</slf4j.version>
<jackson.version>2.9.7</jackson.version>


<!-- when this is next upgraded, see if we can get rid of
javax.activation dependency in tika-server -->


<jaxb.version>2.3.1</jaxb.version>
<cli.version>1.4</cli.version>
<lucene.version>7.5.0</lucene.version>
<mockito.version>2.23.4</mockito.version>

此 pom.xml 中的其他依赖项(其余全部与之前的 pom 相同)

<dependency>
<groupId>biz.aQute</groupId>
<artifactId>bndlib</artifactId>
<version>1.50.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

下面是Build.plugins中所有额外的插件(其余均与之前的pom.xml相同)

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<!-- if this version contains commons-io 2.6, remove hard-coded commons-io version below -->
<version>${forbiddenapis.version}</version>
<configuration>
<targetVersion>${maven.compiler.target}</targetVersion>
<failOnUnresolvableSignatures>false</failOnUnresolvableSignatures>
<failOnUnsupportedJava>false</failOnUnsupportedJava>
<bundledSignatures>
<bundledSignature>jdk-unsafe</bundledSignature>
<bundledSignature>jdk-deprecated</bundledSignature>
<bundledSignature>jdk-non-portable</bundledSignature>
<bundledSignature>jdk-internal</bundledSignature>
<bundledSignature>commons-io-unsafe-${commons.io.version}</bundledSignature>
</bundledSignatures>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>testCheck</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.version}</version>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version> <!-- versions greater than this don't like System.exit calls in tika-batch -->
<configuration>
<argLine>-Xmx3072m -Duser.timezone=UTC</argLine>
</configuration>
</plugin>




<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
</plugin>



<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</plugin>



<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<dependencyConvergence />
<requireMavenVersion>
<version>3.1</version>
</requireMavenVersion>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>

Jacoco 插件也存在于这个 pom 文件中,与之前的 pom 文件相同。

我尝试放入此文件并构建它。没有工作。然后尝试将 jacoco 插件放入根 pom 文件中,但没有成功。给出与上面提到的相同的错误。

请帮忙!!

最佳答案

在我的代码中,我在根pom中的pluginManagement标签下插入jacoco插件:

<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

在我进行单元测试的每个子模块中,我插入以下 pom.xml 配置:

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

您必须仅在有单元测试的java模块内启用jacoco插件。

关于java - 我在 Apache Tika 的 POM 文件中添加 Jacoco Maven 插件来获取代码覆盖率。但我这样做遇到了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56533182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com