Java Module Madness is here now that JavaFX 11 has been released.
I have started using it as dependencies.
Already before JavaFX 11 I had to set
‘–module-path’, classpath.asPath
for compileJava, compileTestJava, javadoc and test.
I didn’t however need to do it for application plugin run task. Until now.
With the JavaFX modules I have now also needed to --add-module for each.
This Gradle configuration has grown. In this regard it no longer has an advantage over Maven, which doesn’t need to set all these flags.
I really hope Gradle is working on making Java 9 module support better, and without all this boilerplate configuration.
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web',
'--add-modules', 'javafx.graphics',
'--add-modules', 'javafx.media'
]
classpath = files()
}
}
compileTestJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web',
'--add-modules', 'javafx.graphics',
'--add-modules', 'javafx.media',
'--add-modules', 'org.junit.jupiter.api',
'--add-reads', "$moduleName=org.junit.jupiter.api",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
]
classpath = files()
}
}
run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web',
'--add-modules', 'javafx.graphics',
'--add-modules', 'javafx.media'
]
}
}
javadoc {
inputs.property("moduleName", moduleName)
doFirst {
exclude "**/module-info.java"
options.addStringOption('-module-path', classpath.asPath)
options.addStringOption('-add-modules', 'javafx.controls')
options.addStringOption('-add-modules', 'javafx.fxml')
options.addStringOption('-add-modules', 'javafx.web')
options.addStringOption('-add-modules', 'javafx.graphics')
options.addStringOption('-add-modules', 'javafx.media')
options.addStringOption('-class-path', "")
options.addBooleanOption('html5', true)
options.addBooleanOption('verbose', true)
}
}
test {
useJUnitPlatform()
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
'--add-modules', 'javafx.fxml',
'--add-modules', 'javafx.web',
'--add-modules', 'javafx.graphics',
'--add-modules', 'javafx.media'
]
}
}