【问题标题】:Maven surefire and JDK 11Maven 万无一失和 JDK 11
【发布时间】:2019-04-25 13:01:25
【问题描述】:

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

  1. 如果我将reuseForks 设置为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. 如果我将其设置为 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

我发现 thisthis 链接描述了相同的问题,但他们没有任何解决方案。

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

【问题讨论】:

  • 您是否尝试过旧版本的 surefire 插件,例如2.21.0?
  • @gjoranv 是的,我有,2.21.0 也有同样的问题
  • 由于某种原因,module-info 类干扰了测试。我已经删除它并且测试工作正常。可能插件还没有为模块化项目做好准备?模块本身也存在问题(可能是由于错误的 openjfx-monocle 依赖关系)。

标签: java maven testing maven-surefire-plugin java-11


【解决方案1】:

似乎在使用模块化项目时test,您需要将forkCount 设置为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>

引用from this article

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


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

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

# 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执行是不可能的?因为-T1CforkCount 0 不能合并。
  • 找到winterbe.com/posts/2018/08/29/…,修复了多线程问题。
  • @Dormouse,实施帖子中的建议如何解决多线程问题?我没有看到任何对线程的引用。
  • --illegal-access=permit,Cesar 如此雄辩地变成了answer,我似乎懒得做。
【解决方案2】:

我在这里找到了解决方案:

https://winterbe.com/posts/2018/08/29/migrate-maven-projects-to-java-11-jigsaw/

我必须添加。

<argLine>
    --illegal-access=permit
</argLine>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
    <configuration>
        <argLine>
            --illegal-access=permit
        </argLine>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.22.0</version>
    <configuration>
        <argLine>
            --illegal-access=permit
        </argLine>
    </configuration>
</plugin>

【讨论】:

  • 这对我在 spring-boot 项目中不起作用。我不得不说 2.21.0 。不知道为什么。否则我会得到一个编译错误:关于反射 api 的东西。
猜你喜欢
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 2019-03-09
  • 2011-05-29
  • 2020-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多