web-dev-qa-db-fra.com

Maven surefire et JDK 11

J'essaie de faire fonctionner Maven surefire sous JDK 11 mais je continue à recevoir ces erreurs:

  1. Si je mets 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. Si je le mets à faux:
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

J'ai trouvé ce et ce lien qui décrivent le même problème mais ils n'ont pas de solution.

Pour la réplication de ce bug, j'ai créé ce dépôt git

6
Gnas

Il semble que lorsque vous utilisez un projet modulaire pour test, vous devez avoir forkCount défini comme 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>

Citant de cet article

Quand module-info.Java est présent et le processus fork est activé, surefire crée un chemin de classe mixte avec des modules et des modules sans nom, ce qui provoque des problèmes de visibilité des modules et empêche le démarrage de l'application.


Remarque: la désactivation des paramètres de configuration forkCount et reuseForks entraîne org.Apache.maven.surefire.booter.SurefireBooterForkException étant lancé, semblable à celui rapporté dans SUREFIRE-1528 .

Si cela peut aider les développeurs de la communauté Maven, le vidage d'exécution de la même exécution se lit comme suit:

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

Voici la ligne de code dans le référentiel source.

11
Naman

J'ai trouvé la solution ici:

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

Je devais ajouter.

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

0