问题
I am trying JDK9 (9-ea+143), and need to set --add-modules java.xml.bind
. I have tried:
- Setting
GRADLE_OPTS="--add-modules java.xml.bind '-Dorg.gradle.jvmargs=--add-modules java.xml.bind'"
- Setting
org.gradle.jvmargs=--add-modules java.xml.bind
in gradle.properties. - Adding
test { jvmArgs '--add-modules java.xml.bind' }
to build.gradle - Adding
tasks.withType(Test) { jvmArgs '--add-modules java.xml.bind' }
to build.gradle - Adding
tasks.withType(JavaExec) { jvmArgs '--add-modules java.xml.bind' }
to build.gradle
Tests still fail. What am I missing?
I have an example project in https://github.com/henrik242/gradle-jdk9-test-problem
✨ ./gradlew build
:compileJava
/foo/gradle-jdk9-test-problem/src/main/java/SomeClass.java:1: error: package javax.xml.bind does not exist
import javax.xml.bind.ValidationException;
^
/foo/gradle-jdk9-test-problem/src/main/java/SomeClass.java:5: error: cannot find symbol
public void doStuff() throws ValidationException {
^
symbol: class ValidationException
location: class SomeClass
/foo/gradle-jdk9-test-problem/src/main/java/SomeClass.java:6: error: cannot find symbol
throw new ValidationException("msg");
^
symbol: class ValidationException
location: class SomeClass
3 errors
:compileJava FAILED
回答1:
It works when adding the following to build.gradle:
compileJava {
options.compilerArgs += ["--add-modules", "java.xml.bind"]
}
compileTestJava {
options.compilerArgs += ["--add-modules", "java.xml.bind"]
}
test {
jvmArgs += ["--add-modules", "java.xml.bind"]
}
Is there an easier way?
EDIT: This also works:
tasks.withType(AbstractCompile) {
options.compilerArgs += ["--add-modules", "java.xml.bind"]
}
tasks.withType(Test) {
jvmArgs += ["--add-modules", "java.xml.bind"]
}
来源:https://stackoverflow.com/questions/40530898/gradle-does-not-honor-add-modules-jvm-argument-in-jdk9