Running javafx application - Error occurred during initialization of boot layer: java.lang.module.ResolutionException

1.4k views Asked by At

As the title says, I'm just trying to run the javafx application. However I have no idea why I'm getting this error, and I don't know why the error is referencing the sisu.inject.bean and aopalliance modules. I don't know wether the module-info.java or the pom.xml is causing the error. Thanks in advance for any anwser.

module-info.java:

module ui {
    requires javafx.fxml;
    requires transitive javafx.graphics;
    requires javafx.controls;
    requires org.testfx.junit5;
    requires junit;
    requires core;
    exports ui.java;
    exports test.ui to junit;
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>it1901.nachwithme</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>ui</artifactId>

    <dependencies>
        <!-- UI imports core as a dependency -->
        <dependency>
            <groupId>it1901.nachwithme</groupId>
            <artifactId>core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- Dependencies for javafx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <exclusions>
                <exclusion>
                    <!-- https://mvnrepository.com/artifact/org.sonatype.sisu/sisu-inject-bean -->
                    <groupId>org.sonatype.sisu</groupId>
                    <artifactId>sisu-inject-bean</artifactId>
                </exclusion>
                <exclusion>
                    <!-- https://mvnrepository.com/artifact/aopalliance/aopalliance -->
                    <groupId>aopalliance</groupId>
                    <artifactId>aopalliance</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Dependencies for javafx -->

        <!-- Dependencies for unit-testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>16-ea+2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit5</artifactId>
            <scope>compile</scope>
        </dependency>
        <!-- Dependencies for unit-testing -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <configuration>
                    <options>
                        <!-- <option>dash dash enable-preview</option> -->
                    </options>
                    <mainClass>ui.java.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.png</include>
                </includes>
            </resource>
        </resources>
        <testSourceDirectory>src/test</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>test</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.png</include>
                </includes>
            </testResource>
        </testResources>
    </build>
</project>

Error:

Error occurred during initialization of boot layer  
java.lang.module.ResolutionException: Modules sisu.inject.bean and aopalliance export package org.aopalliance.aop to module org.testfx

Process finished with exit code 1
2

There are 2 answers

1
deduper On

TL;DR — The two modules have a split package in common. And JPMS forbids split packages.


The long-winded version

The first sentence of this 2010 blog gives a summary of what a split package is…1

…A “split package” is a pretty old Java term where you have packages in different libraries with the same name providing related (or sometimes unrelated functionality)…

Keep in mind that was written in 2010 though; before JPMS. So the blog's claim of „without any problem at both compile and runtime“ in the second sentence is out-of-date; for the modulepath in any case.

For a way more detailed, more up-to-date explanation, watch this Project Jigsaw: Under the Hood video from JavaOne 2016.2

…why the error is referencing the sisu.inject.bean and aopalliance modules…

Because your project has a module descriptor (module-info.java) Maven has put those dependencies — which I can see you declared in your pom — on the modulepath.

…However I have no idea why I'm getting this error…

Because JPMS abhors split packages…3

There are two issues with split packages,

  • if you have the same class in each part of the package, the behavior of your [program] depend on the order in the classpath, i've experienced this kind of bugs with two different libraries requiring different version of ASM, at runtime, a class of the older version was calling a class of the newer version :(
  • security, if you allow split packages, you allow anybody to insert any classes in any packages.

The solution

…
<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.4</version>
    <configuration>
        <options>
            <option>--patch-module</option>
            <option>org.sonatype.sisu=${env.M2_REPO}/aopalliance/aopalliance/1.0/aopalliance-1.0jar</option>
        </options>
        <mainClass>ui.java.App</mainClass>
    </configuration>
</plugin>
…






1 That blog talks about OSGi. But the core split package definition applies to JPMS too.
2 Project Jigsaw: Under The Hood — accompanying slides.
3 Rémi Forax — The split package problem — Jigsaw Dev Mailing List — November 2016.

0
slaszu On

I found another solution. When you use module-info.java file and surefire plugin then the best solution is to use "useModulePath" option

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <useModulePath>false</useModulePath>
    </configuration>
</plugin>

See here Get maven surefire to run on classpath with module-info.java file present