bootstrapClasspath doesn't add to the classpath, but replaces it


(Rivas) #1

According to the docs for JavaExec, the method bootstrapClasspath " Adds the given values to the end of the bootstrap classpath for the process."

That would mean using the jvm option -Xbootclasspath/a, however what happens is that the option -Xbootclasspath is used instad, so the bootstrap classpath is replaced. A simple way to test it:

task javatest(type: JavaExec) {
bootstrapClasspath files(“foo”)
main = “foo.bar”
}

Then run gradle as: ./gradlew javatest --info

And you’ll see the command being invoked is

Command: /usr/bin/java -Xbootclasspath:/tmp/gradle_tests/foo -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant foo.bar

And the failure

java/lang/NoClassDefFoundError: java/lang/Object

While if we run

java -Xbootclasspath/a:/tmp/gradle_tests/foo -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant foo.bar

Then the failure is the expected

Error: Could not find or load main class foo.bar

Three is a very similar question/report in the old forum: JavaExec bootstrapClasspath docs and behaviour don’t match, but hasn’t received any attention.

Is there any way to workaround this?