Say how to run the formatter when the Gradle JVM hides javac · openjavaformat/open-java-format@a9f92e5 · GitHub
Skip to content

Commit a9f92e5

Browse files
committed
Say how to run the formatter when the Gradle JVM hides javac
In a build that applies the plugin and nothing else, formatDiff failed with the raw error from the formatter's first file (#19): class com.palantir.javaformat.java.JavaInput (in unnamed module @0x…) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x… The formatter reads javac's internals, and a plain Gradle daemon exports none of them. Nothing in the error says what to change, and "Formatting <file>" was printed first for a run that could not succeed. JavaFormatExtension, which loads the formatter into the daemon for formatDiff and for the Spotless step, now checks up front whether jdk.compiler exports the five packages the formatter needs to the formatter's class loader. If not, it fails before the first file with the two settings that make the formatter run, the native binary or the --add-exports flags in org.gradle.jvmargs, and the page that explains them. The message lists only the packages that are missing: a Gradle daemon exports com.sun.tools.javac.api and .util on its own, the other three it does not. The native path does not load the formatter into the daemon and is unchanged. Checked in a consumer project against the plugin published to a scratch repository, as #19 asks: without gradle.properties the build fails with the message and touches no file, with the five flags it formats the changed lines. FormatDiffWithoutJavacExportsTest pins the message in the default test task; PalantirJavaFormatPluginTest could not hold it, because that class runs only with the native binary at hand.
1 parent a427d59 commit a9f92e5

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

‎gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java‎

Lines changed: 51 additions & 0 deletions
Lines changed: 97 additions & 0 deletions

0 commit comments

Comments
 (0)