Repository navigation
Description
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
palantirJavaFormatconfiguration is also how a build pins a different formatter version. Keep it as an optional override, or drop it? - IntelliJ integration.
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. - Class loading.
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. - Native binaries. They are per platform and large, so bundling them is probably out of scope. That leaves
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 formatDiff error message, while running the published plugin for the website's Get started pages.
Activity
Say the Gradle plugin carries the formatter and needs no root repository