maven surefire和tycho surefire行为不一致,jacoco未生成报告

maven surefire和tycho surefire行为不一致,jacoco未生成报告,maven,jacoco,tycho,jacoco-maven-plugin,tycho-surefire-plugin,Maven,Jacoco,Tycho,Jacoco Maven Plugin,Tycho Surefire Plugin,我正在为一个项目创建一个pom,并向其中添加测试用例。该项目是一个eclipse插件 使用tycho编译项目效果很好,唯一的问题是在测试期间: 如果我同时运行maven surefire插件测试和tycho surefire插件测试,前者会按预期执行所有测试,而后者会给出以下错误: Execution test of goal org.eclipse.tycho:tycho-surefire-plugin:1.7.0:test failed: Tycho build extension not

我正在为一个项目创建一个pom,并向其中添加测试用例。该项目是一个eclipse插件

使用tycho编译项目效果很好,唯一的问题是在测试期间: 如果我同时运行maven surefire插件测试和tycho surefire插件测试,前者会按预期执行所有测试,而后者会给出以下错误:

Execution test of goal org.eclipse.tycho:tycho-surefire-plugin:1.7.0:test failed: Tycho build extension not configured for MavenProject
我只需将
true
添加到tycho surefire插件中,同时保持maven surefire插件处于打开状态,就可以了;问题甚至在于,jacoco拒绝创建覆盖率站点,并发出以下(非错误)消息:

我试图寻找两者的解决方案,但我发现的任何解决方案的组合都不会使我拥有一个有效的覆盖率站点。 Maven真的让我很困惑,尤其是和tycho在一起,所以我希望在实际修复的基础上有任何解释

这是我的pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
    
    <groupId>mygroupid</groupId>
    <artifactId>myartifactid</artifactId>
    <name>myname</name>
    <packaging>eclipse-test-plugin</packaging>
    
    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <parent>
        <groupId>parentgroupid</groupId>
        <artifactId>parent</artifactId>
        <version>0.9.5</version>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
        </dependency>
        
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>

    <build>
        <testSourceDirectory>src/test/java/</testSourceDirectory>
        <plugins>
            

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                
                <configuration>
                </configuration>

                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <configuration>
                    <output>file</output>
                    <append>true</append>
                    <includes>
                        <include>**/path_to_source/**/*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
         
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>compiletests</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
mygroupid
myartifactid
我的名字
eclipse测试插件
1.7.0
父组ID
父母亲
0.9.5
org.junit.jupiter
JUnitJupiter api
5.6.2
测试
org.junit.jupiter
朱尼特木星发动机
5.6.2
测试
org.jacoco
jacocomaven插件
0.8.5
javassist
javassist
3.12.1.GA
src/test/java/
org.apache.maven.plugins
maven surefire插件
2.12.4
测试
测试
**/测试*.java
测试
org.eclipse.tycho
第谷surefire插件
${tycho版本}
真的
测试
测试
**/测试*.java
测试
org.jacoco
jacocomaven插件
0.8.5
文件
真的
**/到源的路径/**/*
jacoco初始化
配制剂
杰科科遗址
测试
报告
org.apache.maven.plugins
maven编译器插件
2.5.1
编译测试
测试编译
测试编译
这是我的父母pom:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>parentgroupid</groupId>
    <artifactId>parent</artifactId>
    <version>0.9.5</version>
    <packaging>pom</packaging>
    <modules>
        <module>moduleid</module>
    </modules>

    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <repositories>
     <repository>
         <id>eclipse-2020-06</id>
         <layout>p2</layout>
         <url>http://download.eclipse.org/releases/2020-06</url>
     </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
                
                <configuration>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
父组ID
父母亲
0.9.5
聚甲醛
模块ID
1.7.0
eclipse-2020-06
p2
http://download.eclipse.org/releases/2020-06
org.eclipse.tycho
tycho maven插件
${tycho版本}
真的
真的

当然,由于您使用的是非常旧的Surefire版本
2.12.4
,因此不会有任何针对JaCoCo的测试结果。此版本不是为JUnit5创建的。 使用最新版本
3.0.0-M5
,请参阅


如果您想拥有tiny POM,请删除依赖项
junit jupiter引擎
,因为您不需要访问测试代码中的junit内部。Surefire将在测试运行前不久下载它。

当然,由于您使用的是非常旧的Surefire版本
2.12.4
,因此不会有任何JaCoCo的测试结果。此版本不是为JUnit5创建的。 使用最新版本
3.0.0-M5
,请参阅


如果您想拥有tiny POM,请删除依赖项
junit jupiter引擎
,因为您不需要访问测试代码中的junit内部。Surefire将在测试运行前不久下载它。

您的POM有几个错误。让我们先从根本原因开始,然后从高到低依次列出其他优先事项

整个问题是Surefire不了解JaCoCo。你必须用这种方式给“他”打电话(见jacoco.agent),这两种方式都“连接”。请阅读JaCoCo项目中的文件:

<properties>
  <jvm.args.tests>-Xmx2048m -Xms1024m -XX:SoftRefLRUPolicyMSPerMB=50 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</jvm.args.tests>
<properties>
...
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
      </configuration>
...

-Xmx2048m-Xms1024m-XX:SoftRefLRUPolicyMSPerMB=50-Djava.awt.headless=true-Djdk.net.URLClassPath.disableClassPathURLCheck=true
...
maven surefire插件
${jvm.args.tests}${jacoco.agent}
...
下一个错误是如何使用插件。插件jacoco maven插件只能在
<properties>
  <jvm.args.tests>-Xmx2048m -Xms1024m -XX:SoftRefLRUPolicyMSPerMB=50 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</jvm.args.tests>
<properties>
...
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
      </configuration>
...
             <executions>
                <execution>
                    <id>compiletests</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
<packaging>eclipse-test-plugin</packaging>