Maven 万无一失和 JDK 11 [英] Maven surefire and JDK 11

查看:49
本文介绍了Maven 万无一失和 JDK 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 Maven surefire 在 JDK 11 下运行,但我不断收到这些错误:

  1. 如果我将 reuseForks 设置为 true:

<块引用>

 启动fork时出错,检查日志输出进程退出代码:1在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:670)在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)

  1. 如果我将其设置为 false:

<块引用>

目标的执行默认测试 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M1:test失败:java.lang.ClassNotFoundException:org.apache.maven.plugin.surefire.StartupReportConfiguration

我找到了这个他们没有任何解决方案.

为了复制这个错误,我创建了这个 git repo

解决方案

好像在使用模块化项目进行test 时,需要将 forkCount 设置为 0 :

<groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>3.0.0-M1</version><配置><forkCount>0</forkCount><!-- 将其更改为 0 --><reuseForks>false</reuseForks><!-- <threadCount>1</threadCount>--><!-- 应与 'parallel' 一起使用--><printSummary>true</printSummary><!-- <skipTests>false</skipTests>--><!-- 默认为 false --><!-- 在无头模式下运行测试--><systemPropertyVariables><glass.platform>Monocle</glass.platform><monocle.platform>Headless</monocle.platform><prism.order>d3d</prism.order></systemPropertyVariables><argLine>--add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED</argLine></配置></插件>

引用本文

<块引用>

module-info.java 存在且 fork 进程启用时,万无一失创建一个带有模块和未命名模块的混合类路径,导致模块可见性问题并阻止应用程序启动.

<小时>

注意:禁用forkCountreuseForks 配置参数,会导致org.apache.maven.surefire.booter.SurefireBooterForkException 被抛出,类似于 SUREFIRE-1528.

如果这可以帮助 Maven 社区的开发人员,那么来自同一次运行的执行转储内容如下:

# 创建于 2018-11-23T09:31:53.631通过直接写入分叉 JVM 中的本机流来损坏 STDOUT 1. 流在启动层初始化期间发生错误".java.lang.IllegalArgumentException:流标准输入损坏.命令启动层初始化期间发生错误"中的第三个字符后应为逗号.在 org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.(ForkClient.java:507)在 org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine(ForkClient.java:210)在 org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:177)在 org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:88)在 java.base/java.lang.Thread.run(Thread.java:834)

这是源代码库中的代码行.

I'm trying to get Maven surefire to run under JDK 11 but I keep getting these errors:

  1. If I set reuseForks to true:

  Error occurred in starting fork, check output in log
  Process Exit Code: 1
  at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:670)
  at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)
  at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)

  1. If I set it to false:

Execution default-test of goal org.apache.maven.plugins:maven-surefire-   plugin:3.0.0-M1:test
failed: java.lang.ClassNotFoundException: org.apache.maven.plugin.surefire.StartupReportConfiguration

I've found this and this link that describe the same problem but they don't have any solution.

For replication of this bug I created this git repo

解决方案

Seems like while using a modular project to test, you need to have forkCount set as 0 :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M1</version>
    <configuration>
        <forkCount>0</forkCount> <!-- changed this to 0 -->
        <reuseForks>false</reuseForks>
        <!-- <threadCount>1</threadCount> --> <!-- shall be used with 'parallel' -->
        <printSummary>true</printSummary>
        <!-- <skipTests>false</skipTests> --> <!-- defaults to false -->

        <!-- run test in headless mode -->
        <systemPropertyVariables>
            <glass.platform>Monocle</glass.platform>
            <monocle.platform>Headless</monocle.platform>
            <prism.order>d3d</prism.order>
        </systemPropertyVariables>

        <argLine>
            --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
            --add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
        </argLine>
    </configuration>
</plugin>

Quoting from this article

When module-info.java is present and fork process is enabled, surefire creates a mixed classpath with modules and unnamed modules causing module visibility issues and preventing the application to start.


Note: Disabling the forkCount and reuseForks configuration parameters, results in org.apache.maven.surefire.booter.SurefireBooterForkException being thrown, similar to the one reported in SUREFIRE-1528.

If this could help the developers at Maven community, the execution dump from the same run reads the following:

# Created at 2018-11-23T09:31:53.631
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'Error occurred during initialization of boot layer'.
java.lang.IllegalArgumentException: Stream stdin corrupted. Expected comma after third character in command 'Error occurred during initialization of boot layer'.
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.<init>(ForkClient.java:507)
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine(ForkClient.java:210)
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:177)
    at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:88)
    at java.base/java.lang.Thread.run(Thread.java:834)

Here is the line of code in the source repository.

这篇关于Maven 万无一失和 JDK 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆