Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep getting error "automatic module cannot be used with jlink" #140

Open
Saar25 opened this issue Apr 19, 2021 · 5 comments
Open

keep getting error "automatic module cannot be used with jlink" #140

Saar25 opened this issue Apr 19, 2021 · 5 comments

Comments

@Saar25
Copy link

Saar25 commented Apr 19, 2021

My pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <version>1.0.0.Beta2</version>
                <executions>
                    <execution>
                        <id>create-runtime-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>create-runtime-image</goal>
                        </goals>
                        <configuration>
                            <modulePath>
                                <path>${project.build.directory}/modules</path>
                            </modulePath>
                            <modules>
                                <module>org.reflections</module>
                                <module>org.jnativehook</module>
                            </modules>
                            <baseJdk>version=11,vendor=openjdk,platform=windows-x64</baseJdk>
                            <launcher>
                                <name>hackstyle</name>
                                <module>hackstyle.HackStyle</module>
                            </launcher>
                            <outputDirectory>
                                ${project.build.directory}/jlink-image
                            </outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-module-infos</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-module-info</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/modules</outputDirectory>
                            <modules>
                                <module>
                                    <artifact>
                                        <groupId>org.reflections</groupId>
                                        <artifactId>reflections</artifactId>
                                        <version>0.9.11</version>
                                    </artifact>
                                    <additionalDependencies>
                                        <dependency>
                                            <groupId>javax.activation</groupId>
                                            <artifactId>activation</artifactId>
                                            <version>1.1.1</version>
                                        </dependency>
                                    </additionalDependencies>
                                    <moduleInfoSource>
                                        module reflections {
                                        exports org.reflections;
                                        }
                                    </moduleInfoSource>
                                </module>
                                <module>
                                    <artifact>
                                        <groupId>com.1stleg</groupId>
                                        <artifactId>jnativehook</artifactId>
                                        <version>2.1.0</version>
                                    </artifact>
                                    <moduleInfoSource>
                                        module jnativehook {
                                        exports org.jnativehook;
                                        }
                                    </moduleInfoSource>
                                </module>
                            </modules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <configuration>
                    <mainClass>hackstyle.HackStyle</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.1stleg/jnativehook -->
        <dependency>
            <groupId>com.1stleg</groupId>
            <artifactId>jnativehook</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0-b170127.1453</version>
        </dependency>
    </dependencies>

my module-info.java

module hackstyle {
    requires javafx.controls;
    requires jnativehook;
    requires reflections;
    requires java.xml.bind;
    requires java.desktop;
    requires java.logging;

    opens hackstyle.scripts to java.xml.bind;
    exports hackstyle;
}

reflections and jnativehook are automatic modules
I added add-module-info and create-runtime-image goals trying to fix it
but I keep getting "Error: automatic module cannot be used with jlink: reflections from ... "
when I remove these dependencies from tag I get errors saying reflections is not a library...
Did I miss a step?

@aalmiray
Copy link
Contributor

No, you have not missed a step. Automatic Modules do_not work with jlink, by design.

@Saar25
Copy link
Author

Saar25 commented Apr 19, 2021

Then what moditect is for?

@aalmiray
Copy link
Contributor

ModiTect generates a full module descriptor for your project. It does not generate full module descriptors for dependencies. In this case it looks like reflections is an automatic module and not a full module. In order to build a fully modular project/library that can be used with jlink you need all your dependencies (and their transitives) to be fully modular.

This again is a restriction imposed by jlink itself. You can still run the application/project/library in the modulepath (with automatic modules) but cannot create jlink images.

@seanidzenga
Copy link

seanidzenga commented May 13, 2021

@aalmiray Is the add-module-info goal not for adding module descriptors to dependencies?

@aalmiray
Copy link
Contributor

@seanidzenga Ah yes, I missed that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants