Gradle JavaFX Jlink : duplicate module on application module path - java

I have a project working with gradle and everything build and run perfectly but I have issues packaging my application. I work on WSL and would like to have both linux and windows executables but to begin having one is okay I don't really care as long as it works and I can understand how to replicate it on the other OS.
So far, I have read a lot of things on the internet and tried to use this plugin in order to package my application. But when I use gradle jlink, I am warned about a duplicate module issue as you can see below. I have tried many things but cannot find anythign which works or a similar problem on the web. Would you have any clue on what I may be overlooking because of my inexperience?
Thank you in advance !
Starting a Gradle Daemon, 31 busy and 1 incompatible and 12 stopped Daemons could not be reused, use --status for details
> Configure project :
Project : => 'CharacterCreator' Java module
> Task :createMergedModule
error: duplicate module on application module path
module in javafx.base
error: duplicate module on application module path
module in javafx.controls
2 errors
> Task :createMergedModule FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':createMergedModule'.
> Process 'command '/opt/graalvm-svm-java11-linux-gluon-22.1.0.1-Final/bin/javac'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 42m 15s
5 actionable tasks: 3 executed, 2 up-to-date
Here is my gradle.build file :
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.16.2'
}
repositories {
mavenCentral()
mavenLocal()
}
javafx {
version = "19"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
implementation "org.aerofx:aerofx:0.2"
implementation "pdfbox:pdfbox:0.7.3"
implementation "org.javatuples:javatuples:1.2"
implementation "org.controlsfx:controlsfx:11.0.3"
implementation "org.mariadb.jdbc:mariadb-java-client:2.1.2"
implementation "io.gitlab.vincent-lambert:miscellaneousWidgets:1.7"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "org.apache.httpcomponents:httpmime:4.3.1"
}
application {
mainModule = 'CharacterCreator'
mainClass = 'CharacterCreator.Menu.App'
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher{
name = 'hello'
jvmArgs = ['-Dlog4j.configurationFile=./log4j2.xml']
}
}
And my module-info file :
module CharacterCreator {
requires aerofx;
requires javafx.fxml;
requires pdfbox;
requires javatuples;
requires java.sql;
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires org.controlsfx.controls;
requires mariadb.java.client;
requires miscellaneousWidgets;
requires java.desktop;
requires java.net.http;
requires httpmime;
opens CharacterCreator.Creator to javafx.fxml;
exports CharacterCreator.Creator;
opens CharacterCreator.Edits to javafx.fxml;
exports CharacterCreator.Edits;
opens CharacterCreator.Menu to javafx.fxml;
exports CharacterCreator.Menu;
opens CharacterCreator.Misc to javafx.fxml;
exports CharacterCreator.Misc;
opens CharacterCreator.Races to javafx.fxml;
exports CharacterCreator.Races;
opens CharacterCreator.Relations to javafx.fxml;
exports CharacterCreator.Relations;
opens CharacterCreator.Visus to javafx.fxml;
exports CharacterCreator.Visus;
}

I had the same problem, and I found out, that the folder build/jlinkbase/jlinkjars contained mentioned modules for both platform - mac (which I use to develop) and win.
after reading https://github.com/openjfx/javafx-gradle-plugin/issues/65 I just needed to identify the "polluting" library and applied the fix, which was mentioned:
implementation (....) { exclude group:org.openjfx }

Related

How to solve java.lang.module.FindException: Module gson.extras not found?

I have dependencies in build.gradle:
dependencies {
implementation 'com.google.code.gson:gson:2.10'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
implementation 'org.danilopianini:gson-extras:1.1.0'
}
In module-info.java I have:
module qu4lizz.taskscheduler {
requires javafx.controls;
requires javafx.fxml;
requires java.desktop;
requires com.google.gson;
requires gson.extras;
opens qu4lizz.taskscheduler.gui to javafx.fxml;
opens qu4lizz.taskscheduler.my_task to javafx.fxml;
exports qu4lizz.taskscheduler.gui;
exports qu4lizz.taskscheduler.my_task;
}
When I try to build this project I get error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module gson.extras not found, required by qu4lizz.taskscheduler
:GUI.main() (Thread[Execution worker Thread 4,5,main]) completed. Took 0.175 secs.
Execution failed for task ':GUI.main()'.
> Process 'command '/home/qu4lizz/.jdks/corretto-17.0.4.1/bin/java'' finished with non-zero exit value 1
I don't have any idea how to solve this.

What is causing this "jpackage does not exist" error?

I'm trying to make an installer from my Gradle + JavaFX project using jpackage but the following error occurs:
Execution failed for task ':jpackageImage'.
> /home/jonander/.gradle/daemon/6.8/null/bin/jpackage does not exist.
This is my module.info:
module Seftic.main {
requires java.sql;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
}
This is my configuration in build.gradle:
plugins {
id 'java'
id 'org.beryx.jlink' version '2.24.1'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml','javafx.base' ]
}
What is causing this error, and how can it be fixed?
Don't know if anyone found a better solution but, you could set jpackageHome to your JDK install, in your build.gradle:
jlink {
jpackage {
jpackageHome = '/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home'
installerType = 'dmg'
}
}

Gradle module not found in custom uml task

I am using this "plugin" on javadoc to generate a UML Class Diagram with Gradle: https://github.com/talsma-ict/umldoclet
This "plugin" uses javadoc to create UML Class Diagrams.
I am working with the JavaFX library to build my application. When I run my custom task that should generate the image I get an error in my module-info.java that javafx.controls cannot be found.
build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
}
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
umlDoclet
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.18'
// Used for generating UML class diagram
umlDoclet "nl.talsmasoftware:umldoclet:2.0.6"
}
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
task generateUmlClass(type: Javadoc) {
dependsOn("javadoc")
source = sourceSets.main.allJava
destinationDir = reporting.file("uml")
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
mainClassName = "$moduleName/nl.avans.sagrada.MainApp"
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'Sagrada'
}
}
I tried adding dependsOn("javadoc") so I would build first but this doesn't seem to work.
My module-info.java
module Sagrada {
requires javafx.controls;
requires java.sql;
opens nl.avans.sagrada to javafx.base;
opens nl.avans.sagrada.controllers to javafx.controls;
opens nl.avans.sagrada.view.scenes to javafx.controls;
opens nl.avans.sagrada.view.panes to javafx.controls;
opens nl.avans.sagrada.database to java.sql;
exports nl.avans.sagrada;
exports nl.avans.sagrada.controllers;
exports nl.avans.sagrada.view.scenes;
exports nl.avans.sagrada.view.panes;
exports nl.avans.sagrada.interfaces;
exports nl.avans.sagrada.helpers;
exports nl.avans.sagrada.models;
exports nl.avans.sagrada.database;
exports nl.avans.sagrada.database.annotations;
exports nl.avans.sagrada.database.models;
}
Whenever I try to run gradle generateUmlClass it gives following error:
2:55:13 PM: Executing task 'generateUmlClass'...
> Configure project :
Found module name 'Sagrada'
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar
> Task :startScripts
> Task :distTar
> Task :distZip
> Task :assemble
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :build
> Task :generateUmlClass FAILED
D:\Avans\Blok 2\Sagrada-Core\src\main\java\module-info.java:2: error: module not found: javafx.controls
requires javafx.controls;
^
D:\Avans\Blok 2\Sagrada-Core\src\main\java\module-info.java:3: error: module not found: javafx.fxml
requires javafx.fxml;
^
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateUmlClass'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): 'D:\Avans\Blok 2\Sagrada-Core\build\tmp\generateUmlClass\javadoc.options'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
7 actionable tasks: 5 executed, 2 up-to-date
2:55:15 PM: Task execution finished 'generateUmlClass'.
For starters, you are adding two javadoc tasks:
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
task generateUmlClass(type: Javadoc) {
dependsOn("javadoc")
source = sourceSets.main.allJava
destinationDir = reporting.file("uml")
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
}
With same options in both and when you run ./gradlew generateUmlClass you are calling both tasks.
If you add some required options to one of them, the other will miss it. So you should only use one. Let's keep the default task javadoc.
Now:
javadoc {
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
destinationDir = reporting.file("uml")
}
If you run ./gradlew javadoc, you get the errors you have reported:
...src/main/java/module-info.java:2: error: module not found: javafx.controls
requires javafx.controls;
^
This happens because JavaFX is modular, and you should put it in the module-path.
The JavaFX gradle org.openjfx.javafxplugin plugin does precisely that for the run task, but not for the Javadoc one, so to fix the issue we need to add an option to the task with the module-path.
Using gradle's addStringOption, the way to do it is:
javadoc {
options.addStringOption('-module-path', ...)
...
}
The module path now can be taken from the classpath (classpath.asPath), however the JavaFX plugin uses implementation instead of the deprecated compile, so the now we need to use runtimeClasspath:
javadoc {
options.addStringOption('-module-path', configurations.runtimeClasspath.asPath)
...
}
Finally, this is all you should need:
javadoc {
options.addStringOption('-module-path', configurations.runtimeClasspath.asPath)
source = sourceSets.main.allJava
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
destinationDir = reporting.file("uml")
}
Now running ./gradlew javadoc should work successfully.
At least I can get some nice SVG images under `build/reports/uml:
Please let me provide some background to this question which seems resolved already.
I am the author of UMLDoclet; it is a Javadoc Doclet, which is indeed kind of a plugin to the Javadoc tool.
It works as follows:
Call the Standard Doclet from your Javadoc version to generate the regular HTML documentation.
Generate the following PlantUML diagrams:
Class diagram for each documented class
Package diagram for each documented package
Package dependency diagram with a dependency graph containing all documented packages (This was the diagram you shared, it contains many dependency cycles by the way)
Postprocess the generated HTML documents to embed the class, package and dependency diagrams where possible.
Because the doclet uses PlantUML, you have to have Graphviz installed locally when generating the diagrams.
By the way; I would have appreciated it a lot if you had included a link to this Stackoverflow post in the issue you filed in my github repo.
I'm glad your issue was resolved and I'd like to thank José Pereda for his elaborate answer!

Gradle jlink plugin fails during createMergedModule with "the service implementation does not have a default constructor"

I'm using Gradle (4.10.3, but I've tried most versions up through 5.4.1) with JDK 12.0.1 and the org.beryx.jlink plugin (2.10.4), but am running into this error every time I attempt to create the jlink image:
-> Task :createMergedModule
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper$2.run().
Cannot derive uses clause from service loader invocation in:
com/fasterxml/jackson/databind/ObjectMapper.secureGetServiceLoader().
Cannot derive uses clause from service loader invocation in:
org/apache/commons/compress/utils/ServiceLoaderIterator.().
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:393:
error: the service implementation does not have a default constructor:
XBeansXPath
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with
org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
C:\Users\MyName\IdeaProjects\myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394:
error: the service implementation does not have a default constructor:
XBeansXQuery
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with
org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
2 errors
-> Task :createMergedModule FAILED
When I click through to the lines throwing the errors in the merged module-info.java, it points to these two:
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
My build.gradle file looks like this:
plugins {
id 'application'
id 'idea'
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'org.beryx.jlink' version '2.10.4'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-csv:1.6'
compile 'org.apache.poi:poi-ooxml:4.1.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.5.0-M1'
}
// ### Application plugin settings
application {
mainClassName = "$moduleName/path.to.myapp"
}
// ### Idea plugin settings
idea {
module {
outputDir = file("out/production/classes")
}
}
// ### Java plugin settings
sourceCompatibility = JavaVersion.VERSION_11
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
test {
useJUnitPlatform()
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}
// ### JavaFX plugin settings
javafx {
version = "12.0.1"
modules = ['javafx.controls', 'javafx.fxml']
}
// ### jlink plugin settings
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
Any ideas on how I can address this?
The following possible solution is based just on your build file, without knowing about your module-info or the project's code, so it might not work.
It is also based on this issue at the jlink plugin's repository.
First, let me explain how this plugin works: since the (JDK) jlink tool doesn't allow non-modular dependencies, the plugin will try to collect all of them and create on the fly a module, that can be added to the module-path. This module is named $yourModuleName.mergedModule.
Now I'm adding your dependencies to a simple JavaFX project. When I run ./gradlew jlink I get the same errors you have posted. If you check the errors:
myapp\build\jlinkbase\tmpjars\myapp.merged.module\module-info.java:394: error
This shows that the created module is named myapp.merged.module, and that it has a module-info descriptor. If you open it you will see all the exports (the module will export every package of the dependencies by default), the requires and the provides:
open module myapp.merged.module {
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
requires java.xml.crypto;
requires java.logging;
requires java.sql;
requires java.xml;
requires java.desktop;
requires java.security.jgss;
requires jdk.javadoc;
uses java.nio.file.spi.FileSystemProvider;
provides com.fasterxml.jackson.core.JsonFactory with com.fasterxml.jackson.core.JsonFactory;
provides com.fasterxml.jackson.core.ObjectCodec with com.fasterxml.jackson.databind.ObjectMapper;
provides org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface with org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery;
provides org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface with org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath;
}
So now the question is: should you add some more requirements to your own module? The answer is explained here: that will increase unnecessary your project's size. A better way is to use the mergedModule script block:
The mergedModule block allows you to configure the module descriptor of the merged module
And:
the module descriptor is created using the algorithm implemented by the suggestMergedModuleInfo task.
If you run ./gradlew suggestMergedModuleInfo you will basically get the same contents for the merged module descriptor as above.
A possible solution is to start just adding some requires to the merged module descriptor, and try again.
I started with:
jlink {
mergedModule {
requires "java.xml"
}
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'myapp'
}
}
and I could run ./gradlew jlink successfully.
If you check the merged module descriptor now, it will look like:
open module myapp.merged.module {
requires java.xml;
exports com.fasterxml.jackson.annotation;
exports com.fasterxml.jackson.core;
exports com.fasterxml.jackson.core.async;
...
exports schemaorg_apache_xmlbeans.system.sXMLTOOLS;
}
containing only the explicit requires, all the exports, but without provides, so the errors will be gone.
Since I don't have your code, I can't say if this will work for you, but it did for me with the same dependencies.

java 10 gradle project : automatic module not found

I created a java 10 project with intelliJ, using gradle.
I copied some stuff into it (some "AppFx" class using the library guava and javaFx, and a personal build.gradle file).
I also added a module-info.java file in src/main/java with this content:
module biblio5.main {
requires javafx.graphics;
requires javafx.controls;
requires javafx.base;
requires guava;
}
in which grava is an automatic module.
here is the relevant part of build.gradle:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
intelliJ can compile the project (using the hammer-like icon) but when I run the compileJava gradle task from intelliJ, I get an error:
13:12:46: Executing task 'compileJava'...
Task :compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5:
error: module not found: guava
requires guava;
^ 1 error
I spent a lot of time on the net but did not manage to find an answer.
thank you
ps: here is the entire build.gradle:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
}
repositories {
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
jcenter()
}
}
plugins {
id 'java'
id 'application'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'eu.appsatori.fatjar'
group 'lorry'
version '1'
sourceCompatibility = 1.10
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
//********************************************************************************************
launch4j {
outfile='bibliotek-v3.exe'
mainClassName = 'lorry.AppFx'
icon = "${projectDir}\\icons\\hands2.ico"
copyConfigurable = project.tasks.fatJar.outputs.files
//jar = "lib/${project.tasks.fatJar.archiveName}"
//headerType = "console"
jar = "${buildDir}\\productFatJar\\fat.jar"
}
jar {
baseName = 'executable3'
version = ''
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task copyExecutable(type: Copy) {
from file("${buildDir}\\launch4j\\bibliotek-v3.exe")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyJar(type: Copy) {
from file("${buildDir}\\jfx\\app\\bibliotek-v3.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
task copyFatJar(type: Copy) {
from file("${buildDir}\\productFatJar\\fat.jar")
into file("c:\\Users\\lolve\\Documents\\gradle_java\\produits")
}
createExe.doLast{
tasks.copyExecutable.execute()
}
task createJar(){
doLast{
tasks.jfxJar.execute()
tasks.jfxNative.execute()
tasks.copyJar.execute()
}
}
jfx {
jfxMainAppJarName = "bibliotek-v3.jar"
// minimal requirement for jfxJar-task
mainClass = 'lorry.AppFx'
// minimal requirement for jfxNative-task
vendor = 'lolveley'
}
fatJar {
destinationDir=file("${buildDir}\\productFatJar")
archiveName="fat.jar"
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'lorry.AppFx'
)
}
}
task createFats(){
doLast{
tasks.fatJar.execute()
tasks.copyFatJar.execute()
tasks.createExe.execute()
}
}
EDIT
well, I made the change, and now I have "com.google.commons" instead guava in module-info.java, but I still get this error:
Testing started at 14:20 ... 14:20:14: Executing task 'check'...
Task :compileJava FAILED C:\Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5:
error: module not found: com.google.common
requires com.google.common;
^ 1 error
I changed gradle in intelliJ (the default option - recommended - was "default gradle wrapper") to my local gradle (v4.9), but without any effect.
What do you mean by "compatible with java"? What about try with a java 9 installation?
Update: Gradle 6.4 added basic support for Jigsaw modules. See this sample in the documentation (which also links to other related documentation). Note that the Building Java 9 Modules article linked to in this answer has changed significantly since this answer was posted.
The issue is Gradle still (as of 4.10-rc-2) doesn't have first-class support for Jigsaw modules. All the tasks will use the classpath, not the modulepath, when executing. This obviously will cause issues when trying to create a modular library/application (with module-info.java).
If you want to use Jigsaw modules in your project you should read Building Java 9 Modules. Your scenario, as #nullpointer mentions, is best covered by this section of the linked document. The takeaway is to add the following to your build.gradle file:
ext.moduleName = 'your.module'
compileJava {
inputs.property('moduleName', moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath
]
classpath = files()
}
}
They also have sections for modifying the compileTestJava task (here) and the test task (here). Personally, I tend to not modify those tasks as testing often requires a lot of reflection which in turn requires a lot of --add-opens arguments. If you find out that's not true (haven't tried it in a while) or there's a better way, please let me know.
If your Gradle project is an application you also want to read the section covering the run and assemble tasks.
There is an experimental Gradle plugin that does all this for you: experimental-jigsaw. The plugin is limited, however, and there is a fork on GitHub, named chainsaw, that adds more features. Note: I don't know how maintained either plugin is.
Another Gradle plugin is available: Gradle Modules Plugin.
If you want to watch for updates regarding Jigsaw support in Gradle they maintain an epic on GitHub.
Also, to include what #nullpointer commented, you should be using a version of Guava that includes an Automatic-Module-Name entry in its manifest. Without this entry (combined with no module-info) the name of the module is subject to the name of the jar file; which may change unexpectedly. In other words, the Automatic-Module-Name entry makes for a better contract regarding the name of an automatic module. The first version that Guava added this entry is 23.2:
Changelog
Added JPMS module name com.google.common for Guava.
...
However, the most recent version (as of writing this answer) is 26.0.
More information about automatic modules can be found:
in the Javadoc of ModuleFinder.of(Path...)
this section of The State of the Module System
and this Stack Overflow question

Categories