What happens
The formatter is not part of the plugin. PalantirJavaFormatProviderPlugin creates the palantirJavaFormat configuration in the root project, with a default dependency on dev.openjavaformat:open-java-format:<plugin version>, and the native formatter gets palantirJavaFormatNative the same way. Both are resolved when formatDiff runs, from the root project's repositories.
A multi-project build that declares repositories only in its subprojects therefore fails:
> Failed to query the value of task ':app:formatDiff' property 'nativeImage'.
> Could not resolve all files for configuration ':palantirJavaFormatNative'.
> Cannot resolve external dependency dev.openjavaformat:open-java-format-native:2.98.0.1
because no repositories are defined.
This was observed with plugin 2.98.0.1, Gradle 9.7.1 and openjavaformat.native.formatter=true. The Java-based formatter resolves :palantirJavaFormat in the root project in the same way.
Proposal
Carry the formatter jar inside the plugin. The Java-based formatter then needs nothing from the consumer's repositories, and its version always matches the plugin's.
To decide along the way
- Version override. The
palantirJavaFormat configuration is also how a build pins a different formatter version. Keep it as an optional override, or drop it?
- IntelliJ integration.
UpdatePalantirJavaFormatIdeaXmlFile and ConfigureJavaFormatterXml write the configuration's files into .idea/open-java-format.xml as implementationClassPath. A bundled jar needs a stable file location that the IDE plugin can load, for example a copy in a cache directory, as NativeImageAtomicCopy already does for the native image.
- Class loading.
JavaFormatExtension.serviceLoad loads the formatter through its own URLClassLoader. Bundling should keep that isolation, so that the formatter's dependencies do not meet the build's classpath.
- Native binaries. They are per platform and large, so bundling them is probably out of scope. That leaves
palantirJavaFormatNative with the repository requirement, which is worth either solving separately or stating clearly in the error.
Until then
The workaround is documented at https://openjavaformat.dev/get-started/gradle/#multi-project-builds: declare mavenCentral() for all projects, the root included.
Found together with #19, the formatDiff error message, while running the published plugin for the website's Get started pages.
What happens
The formatter is not part of the plugin.
PalantirJavaFormatProviderPlugincreates thepalantirJavaFormatconfiguration in the root project, with a default dependency ondev.openjavaformat:open-java-format:<plugin version>, and the native formatter getspalantirJavaFormatNativethe same way. Both are resolved whenformatDiffruns, from the root project's repositories.A multi-project build that declares repositories only in its subprojects therefore fails:
This was observed with plugin 2.98.0.1, Gradle 9.7.1 and
openjavaformat.native.formatter=true. The Java-based formatter resolves:palantirJavaFormatin the root project in the same way.Proposal
Carry the formatter jar inside the plugin. The Java-based formatter then needs nothing from the consumer's repositories, and its version always matches the plugin's.
To decide along the way
palantirJavaFormatconfiguration is also how a build pins a different formatter version. Keep it as an optional override, or drop it?UpdatePalantirJavaFormatIdeaXmlFileandConfigureJavaFormatterXmlwrite the configuration's files into.idea/open-java-format.xmlasimplementationClassPath. A bundled jar needs a stable file location that the IDE plugin can load, for example a copy in a cache directory, asNativeImageAtomicCopyalready does for the native image.JavaFormatExtension.serviceLoadloads the formatter through its ownURLClassLoader. Bundling should keep that isolation, so that the formatter's dependencies do not meet the build's classpath.palantirJavaFormatNativewith the repository requirement, which is worth either solving separately or stating clearly in the error.Until then
The workaround is documented at https://openjavaformat.dev/get-started/gradle/#multi-project-builds: declare
mavenCentral()for all projects, the root included.Found together with #19, the
formatDifferror message, while running the published plugin for the website's Get started pages.