Skip to content

Ship the formatter jar inside the Gradle plugin instead of resolving it from the root project #20

Description

@abashev

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions