Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Maven中使用JUnit5和Java10,并确认Maven surefire插件和org.ow2.asm_Java_Maven_Junit_Maven Surefire Plugin_Maven Compiler Plugin - Fatal编程技术网

如何在Maven中使用JUnit5和Java10,并确认Maven surefire插件和org.ow2.asm

如何在Maven中使用JUnit5和Java10,并确认Maven surefire插件和org.ow2.asm,java,maven,junit,maven-surefire-plugin,maven-compiler-plugin,Java,Maven,Junit,Maven Surefire Plugin,Maven Compiler Plugin,在我的项目中,我尝试将Java10与JUnit5结合使用,但发生了一些有趣的事情 背景 为了使maven在Java10下正常工作,我们需要将maven编译器插件的asm库更改为org.ow2.asm。为了使JUnit5在Java10下正常工作,我们需要maven surefire插件。这是我的pom.xml的插件部分 <plugins> <plugin> <groupId>org.apache.maven.plugins

在我的项目中,我尝试将Java10与JUnit5结合使用,但发生了一些有趣的事情

背景
为了使maven在Java10下正常工作,我们需要将
maven编译器插件的asm库
更改为
org.ow2.asm
。为了使JUnit5在Java10下正常工作,我们需要
maven surefire插件
。这是我的
pom.xml
插件部分

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>10</source>
                <release>10</release>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>${asm.version}</version> <!-- Use newer version of ASM -->
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefile.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>${junit.platform.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
org.objectweb.asm.ClassReader上的
java.lang.IllegalArgumentException
真的很奇怪,也许
org.ow2.asm
maven surefire插件
不兼容


你们有什么解决办法吗?由于种种原因,我无法更改Java的版本,也许更改为JUnit4会有所帮助?

经过长时间的讨论,我们终于成功了。以下是解决方案: 整个讨论就在这里:


org.apache.maven.plugins
maven编译器插件
3.7.0
${java.version}
${java.version}
真的
org.ow2.asm
asm
${asm.version}
maven surefire插件
${surefile.version}
org.junit.platform
junit平台surefire提供程序
${junit.platform.version}
org.ow2.asm
asm
${asm.version}

砰的一声,一切顺利

您应该切换到Maven Surefire插件(2018年6月发布)的版本2.22.0,这也将允许您摆脱junit平台Surefire提供程序的依赖关系:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
</plugin>


),它引入了ASM版本6.1.1,并提供了适当的Java 10支持。有关更多信息,请参阅。

您有项目示例吗?Github?@khmarbaise,当然。由于这是一个未完成的Postgres项目,恐怕我不能保证你能在你的机器上成功运行它。你尝试过junit5/surefire的哪个版本组合?它们并非都兼容。嘿,伙计们!最后我成功了。原因是最新版本的
maven-surefire-plugin
具有错误的依赖性
org.codehaus.plexus:plexus-java:jar:0.9.3
,这与java 10不兼容。因此,您需要手动更换它。
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <verbose>true</verbose>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>${asm.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefile.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>${junit.platform.version}</version>
                </dependency>
              <!-- Change the depedency manually -->
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>${asm.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
</plugin>