My question: How do I set a module path for gradle build
?
I've become comfortable working with Java modules from the command line. I do a frequent exercise in Powershell which results in these source files.
└───src
├───appMod
│ │ module-info.java
│ │
│ └───appPack
│ Entry.java
│
└───greetMod
│ module-info.java
│
└───greetPack
Hello.java
appMod/module-info
module appMod {
requires greetMod;
}
appMod/appPack.Entry
package appPack;
import greetPack.Hello;
public class Entry {
public static void main(String[] args) {
System.out.println(new Hello().sayHello());
}
}
greetMod/module-info
module greetMod {
exports greetPack;
}
greetMod/greetPack.Hello
package greetPack;
public class Hello {
public String sayHello() {
return "Greetings from Hello class!";
}
}
Since the appMod module requires greetMod, I compile and jar greetMod first.
javac -d out/greetMod src/greetMod/module-info.java src/greetMod/greetPack/Hello.java;
jar cf lib/greetJar.jar -C out/greetMod .;
Then I compile and jar appMod, but as I do so I specify the module path (-p) where the new greetMod jar (greetJar) can be found (in lib).
javac -d out/appMod -p lib src/appMod/module-info.java src/appMod/appPack/Entry.java;
jar cfe lib/appJar.jar appPack.Entry -C out/appMod .;
I can then run this or jlink it in part by adding a module path.
java -p lib -m appMod;
jlink -p lib --add-modules appMod --launcher launch=appMod --output dist;
dist/bin/launch
I now want to do this same exercise in Gradle, but I can't figure out how to do the equivalent of setting a module path such as -p lib
. I've seen code for sourceSets, and countless variations of dependencies, but so far I haven't been able to put together something that works. I've also read conflicting statements that both say that Gradle doesn't fully support Java modules, and that Gradle does support them.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…