Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default versions for palantir-java-format #1774

Closed
basil opened this issue Aug 1, 2023 · 7 comments · Fixed by #1920
Closed

Update default versions for palantir-java-format #1774

basil opened this issue Aug 1, 2023 · 7 comments · Fixed by #1920

Comments

@basil
Copy link

basil commented Aug 1, 2023

Summary of problem

Spotless Maven Plugin (Palantir Java Format) does not work on Java 21. It works fine on Java 17.

Maven version

Apache Maven 3.9.2

Spotless version

2.38.0

Operating system and version

OS name: "linux", version: "5.15.0-78-generic", arch: "amd64", family: "unix"
OpenJDK Runtime Environment (build 21-ea+32-2482) 2023-09-19

Configuration

https://github.com/jenkinsci/plugin-pom/blob/master/pom.xml

Can be reproduced by cloning e.g. https://github.com/jenkinsci/text-finder-plugin and running mvn clean verify -DskipTests.

Stack trace

[INFO] --- spotless:2.38.0:check (default) @ text-finder ---
[INFO] Index file does not exist. Fallback to an empty index
[ERROR] Step 'palantir-java-format' found problem in 'src/test/java/hudson/plugins/textfinder/test/TestEchoBuilder.java':
'com.sun.tools.javac.tree.JCTree com.sun.tools.javac.tree.JCTree$JCImport.getQualifiedIdentifier()'
java.lang.NoSuchMethodError: 'com.sun.tools.javac.tree.JCTree com.sun.tools.javac.tree.JCTree$JCImport.getQualifiedIdentifier()'
    at com.palantir.javaformat.java.RemoveUnusedImports.getSimpleName (RemoveUnusedImports.java:245)
    at com.palantir.javaformat.java.RemoveUnusedImports.buildReplacements (RemoveUnusedImports.java:225)
    at com.palantir.javaformat.java.RemoveUnusedImports.removeUnusedImports (RemoveUnusedImports.java:209)
    at com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc.apply (PalantirJavaFormatFormatterFunc.java:42)
    at com.diffplug.spotless.FormatterFunc.apply (FormatterFunc.java:32)
    at com.diffplug.spotless.FormatterStepImpl$Standard.format (FormatterStepImpl.java:82)
    at com.diffplug.spotless.FormatterStep$Strict.format (FormatterStep.java:103)
    at com.diffplug.spotless.Formatter.compute (Formatter.java:246)
    at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:203)
    at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:190)
    at com.diffplug.spotless.maven.SpotlessCheckMojo.process (SpotlessCheckMojo.java:54)
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:229)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
@basil
Copy link
Author

basil commented Aug 1, 2023

This was fixed upstream in palantir/palantir-java-format#886 and released in 2.33.0 but

private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0");
has not adopted the new release.

@nedtwigg
Copy link
Member

nedtwigg commented Aug 1, 2023

You can set the version manually as a workaround. I think it's like this: <palantirJavaFormat><version>2.33.0</version></palantirJavaFormat>

@nedtwigg nedtwigg changed the title Spotless Maven Plugin does not work on Java 21 Update default versions for palantir-java-format Aug 1, 2023
@basil
Copy link
Author

basil commented Aug 1, 2023

This was fixed upstream in palantir/palantir-java-format#886 and released in 2.33.0

Ostensibly fixed, but both 2.33.0 and 2.34.0 do not work for me: palantir/palantir-java-format#885 (comment)

@basil
Copy link
Author

basil commented Aug 2, 2023

The first fix was incomplete. palantir/palantir-java-format#909 solves the problem and I have verified the fix locally.

@basil
Copy link
Author

basil commented Aug 7, 2023

This was released in 2.35.0 and I have verified the fix locally. Suggest the following patch:

diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
index f769ad09..24bd6434 100644
--- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
+++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
@@ -30,7 +30,7 @@ public class PalantirJavaFormatStep {
     private static final String DEFAULT_STYLE = "PALANTIR";
     private static final String NAME = "palantir-java-format";
     private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
-    private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0");
+    private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.35.0");
 
     /** Creates a step which formats everything - code, import order, and unused imports. */
     public static FormatterStep create(Provisioner provisioner) {

@nedtwigg
Copy link
Member

nedtwigg commented Dec 4, 2023

Published in plugin-gradle 6.23.3 and plugin-maven 2.41.1.

@steven-sheehy
Copy link
Contributor

The above fix seems like it's not enough for Java 21 support in my codebase. I opened #1944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants