I try to develop a little example in Java 9 with Gradle. But I don't find the exact option to make a working run config. I've tried to copy the right parts from this little tutorial. But the run task does just get an error
java.lang.module.FindException: Module de.project.crawler not found
Obviously there is a mistake with the module path which I gave Gradle but I don't know how to fix this.
My working directory
project/
crawler/
| src/
| | main/
| | | java/
| | | | de.project.crawler/
| | | | | Main.java
| | module-info.java
| build.gradle
| settings.gradle
build.gradle
settings.gradle
build.gradle:
subprojects {
afterEvaluate {
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
}
}
crawler/build.gradle:
plugins {
id 'java-library'
id 'application'
}
ext.moduleName = 'de.project.crawler'
mainClassName = 'de.project.crawler/de.project.crawler.Main'
repositories {
jcenter()
}
run {
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--module', mainClassName
]
classpath = files()
}
}
startScripts {
inputs.property("moduleName", moduleName)
doFirst {
classpath = files()
defaultJvmOpts = [
'--module-path', 'APP_HOME_LIBS',
'--module', mainClassName
]
}
}
crawler/src/module-java.info
module de.project.crawler {
}
crawler/src/main/java/de.project.crawler/Main.java
package de.project.crawler;
public class Main {
public static void main(String[] args) {
System.out.println("Hallo");
}
}
So, if I try this in IntelliJ everything is working. If I try this on cmd, compile with java9 and run it, everything is working. If I try 'gradle run' he states the error which I gave you in the introduction.
The module-info.java was on the wrong position. This file has to be on src/main/java
in the module. This is the right structure:
project/
crawler/
| src/
| | main/
| | | java/
| | | | de.project.crawler/
| | | | | Main.java
| | | | module-info.java
| build.gradle
| settings.gradle
build.gradle
settings.gradle
Thanks Alan Bateman from the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With