11

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

Naman
  • 27,789
  • 26
  • 218
  • 353
Gnas
  • 698
  • 1
  • 6
  • 14
  • Have you tried older versions of the surefire plugin, e.g. 2.21.0? – gjoranv Nov 22 '18 at 21:31
  • @gjoranv Yes I have, same problem on 2.21.0 – Gnas Nov 22 '18 at 21:34
  • For some reason, the `module-info` class is interfering with the test. I've removed it and the test works fine. Probably the plugin is not ready for modular projects yet? Also there is an issue with the module itself (due to wrong openjfx-monocle dependencies probably). – José Pereda Nov 22 '18 at 23:27

2 Answers2

15

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 1
    Though in my understanding this would result in the tests being run using the classpath and not the modulepath. – Naman Nov 23 '18 at 03:46
  • So this mean parallel maven execution is impossible? Because `-T1C` and `forkCount` 0 can't be combined. – Dormouse Jan 28 '19 at 15:35
  • 1
    Found https://winterbe.com/posts/2018/08/29/migrate-maven-projects-to-java-11-jigsaw/, which fixes the multithreaded issue. – Dormouse Jan 28 '19 at 15:47
  • @Dormouse, how does implementing the suggestions in the post address the multithreaded issue? I don't see any references to threading. – Eric Feb 09 '21 at 09:52
  • It was the `--illegal-access=permit`, that Cesar so eloquently turned into an [answer](https://stackoverflow.com/a/58651001/883603), which I seem to have been too lazy for. – Dormouse Feb 09 '21 at 15:49
6

I found the solution here:

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

I had to add.

<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>

  • 1
    This did not work for me on a spring-boot project. I had to say at 2.21.0 . Not sure why. Otherwise I was getting a compile error: something about Reflection api. – djangofan Feb 26 '21 at 19:17