revelc / impsort-maven-plugin

Java import sorter plugin. Sort your imps!
https://code.revelc.net/impsort-maven-plugin
Apache License 2.0
55 stars 27 forks source link

Plugin fails with upcoming Maven 3.9.0 #64

Closed cstamas closed 1 year ago

cstamas commented 1 year ago

Describe the bug The impsort-maven-plugin depends on a Maven2 feature that is about to be removed in Maven 3.9,0 and Maven 4.0,0: "auto injection" of plexus-utils. In short: plugin uses but does NOT declares COMPILE dependency on plexus-utils. Maven2 was making plexus-utils "provided", while Maven 3.x supported this for backward compatilibty reasons, but Maven 3,9 and later will not.

Versions (OS, Maven, Java, and others, as appropriate):

To Reproduce

  1. build locally Maven 3.9 or 4.0 snapshot
  2. build some project using this plugin (for example maven daemon)
  3. See error
    [ERROR] Failed to execute goal net.revelc.code:impsort-maven-plugin:1.7.0:sort (sort-imports) on project mvnd-build-maven-plugin: Execution sort-imports of goal net.revelc.code:impsort-maven-plugin:1.7.0:sort failed: A required class was missing while executing net.revelc.code:impsort-maven-plugin:1.7.0:sort: null
    [ERROR] -----------------------------------------------------
    [ERROR] realm =    plugin>net.revelc.code:impsort-maven-plugin:1.7.0
    [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
    [ERROR] urls[0] = file:/home/cstamas/.m2/repository-oss/net/revelc/code/impsort-maven-plugin/1.7.0/impsort-maven-plugin-1.7.0.jar
    [ERROR] urls[1] = file:/home/cstamas/.m2/repository-oss/com/github/javaparser/javaparser-core/3.24.2/javaparser-core-3.24.2.jar
    [ERROR] urls[2] = file:/home/cstamas/.m2/repository-oss/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar
    [ERROR] urls[3] = file:/home/cstamas/.m2/repository-oss/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar
    [ERROR] urls[4] = file:/home/cstamas/.m2/repository-oss/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
    [ERROR] urls[5] = file:/home/cstamas/.m2/repository-oss/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
    [ERROR] urls[6] = file:/home/cstamas/.m2/repository-oss/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar
    [ERROR] urls[7] = file:/home/cstamas/.m2/repository-oss/com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar
    [ERROR] urls[8] = file:/home/cstamas/.m2/repository-oss/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar
    [ERROR] Number of foreign imports: 1
    [ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
    [ERROR] 
    [ERROR] -----------------------------------------------------

Expected behavior To work as before.

ctubbsii commented 1 year ago

For what it's worth, every PR in GitHub is also an issue. If you're going to immediately submit a PR, it's not strictly necessary to create an issue first. It's not a huge problem, and there are good reasons to do it sometimes, but it does double up the issue tracker, so just wanted to mention you don't have to do it for this project.

gnodet commented 1 year ago

@ctubbsii Do you plan a release soon ? Maven 4.0.0-alpha-2 has been released already and exhibits the same problem, which makes it unusable in any project using this plugin.

ctubbsii commented 1 year ago

@gnodet I released today.

sbernard31 commented 1 year ago

I faced this issue too and if I correctly understand this is now fixed in recent version. Probably since v1.8.0 ?

But for some reason my build target java8 and so is stuck to v1.6.x of this plugin. I know I could use maven toolchain but this make the build more complicated to use but I try to keep it as easy as possible to build because this is an open source project.

@ctubbsii do you think this is possible to also backport the fix in v1.6.x and so release a new v1.6.3 with it ?

Waiting I used this workaround :

<plugin>
  <groupId>net.revelc.code</groupId>
  <artifactId>impsort-maven-plugin</artifactId>
  <!--  stuck to 1.6.x for java8 compatibility -->
  <version>1.6.2</version>
  <dependencies>
    <!-- Needed because of maven 3.9.0 backward compatibility issue,
         See : https://github.com/revelc/impsort-maven-plugin/issues/64 -->
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-utils</artifactId>
      <version>3.5.1</version>
    </dependency>
  </dependencies>
</plugin>
hazendaz commented 1 year ago

I'd suggest using jdk 11 to build. Your product will still target java 8 or whatever you told it. There is little to no reason to use toolchains or continue using java 8. There are already a good number of plugins that require java 11 and stopped supporting java 8. Additionally, if it's a must to stay where you are, then it would be best to stay on maven 3.8.x which is still supported.

I cannot speak for final decision in the end but don't see the value of trying to continue jdk 8 support when it's so well proven unnecessary from a build perspective.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Simon @.> Sent: Monday, March 6, 2023 6:06:31 AM To: revelc/impsort-maven-plugin @.> Cc: Subscribed @.***> Subject: Re: [revelc/impsort-maven-plugin] Plugin fails with upcoming Maven 3.9.0 (Issue #64)

I faced this issue too and if I correctly understand this is now fixed in recent version. Probably since v1.8.0 ?

But for some reason my build target java8 and so is stucked to v1.6.x of this plugin. I know I could use toolchain but this make the build more complicated to use and which I would like to avoid as this is an open source project which should be as easy as possible to build.

@ctubbsiihttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fctubbsii&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934378379%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dulHua5LpypWCCIuVMlsW5EA1QsRKp8KF3W42gd47Q0%3D&reserved=0 do you think this is possible to also backport the fix in v1.6.x and so release a new v1.6.3 with it ?

Waiting I used this workaround :

net.revelc.code impsort-maven-plugin 1.6.2 org.codehaus.plexus plexus-utils 3.5.1

— Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frevelc%2Fimpsort-maven-plugin%2Fissues%2F64%23issuecomment-1455926791&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934378379%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=UT3X7r9PpN93uKkNSn3GOi8XOhT7T1TzjUMsrRqMJwM%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODIYXT43WM5XWQPOTIPDW2XALPANCNFSM6AAAAAASAELQYA&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934534623%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9Lggf3E8cYhkAKlcEOWV2HhcjVuKa67op3hU1B3HQus%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

hazendaz commented 1 year ago

And of course you have a simple workaround. Many plugins need the same especially if not typical usage or no longer supported.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jeremy Landis @.> Sent: Monday, March 6, 2023 8:50:21 AM To: revelc/impsort-maven-plugin @.>; revelc/impsort-maven-plugin @.> Cc: Subscribed @.> Subject: Re: [revelc/impsort-maven-plugin] Plugin fails with upcoming Maven 3.9.0 (Issue #64)

I'd suggest using jdk 11 to build. Your product will still target java 8 or whatever you told it. There is little to no reason to use toolchains or continue using java 8. There are already a good number of plugins that require java 11 and stopped supporting java 8. Additionally, if it's a must to stay where you are, then it would be best to stay on maven 3.8.x which is still supported.

I cannot speak for final decision in the end but don't see the value of trying to continue jdk 8 support when it's so well proven unnecessary from a build perspective.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Simon @.> Sent: Monday, March 6, 2023 6:06:31 AM To: revelc/impsort-maven-plugin @.> Cc: Subscribed @.***> Subject: Re: [revelc/impsort-maven-plugin] Plugin fails with upcoming Maven 3.9.0 (Issue #64)

I faced this issue too and if I correctly understand this is now fixed in recent version. Probably since v1.8.0 ?

But for some reason my build target java8 and so is stucked to v1.6.x of this plugin. I know I could use toolchain but this make the build more complicated to use and which I would like to avoid as this is an open source project which should be as easy as possible to build.

@ctubbsiihttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fctubbsii&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934378379%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dulHua5LpypWCCIuVMlsW5EA1QsRKp8KF3W42gd47Q0%3D&reserved=0 do you think this is possible to also backport the fix in v1.6.x and so release a new v1.6.3 with it ?

Waiting I used this workaround :

net.revelc.code impsort-maven-plugin 1.6.2 org.codehaus.plexus plexus-utils 3.5.1

— Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frevelc%2Fimpsort-maven-plugin%2Fissues%2F64%23issuecomment-1455926791&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934378379%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=UT3X7r9PpN93uKkNSn3GOi8XOhT7T1TzjUMsrRqMJwM%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODIYXT43WM5XWQPOTIPDW2XALPANCNFSM6AAAAAASAELQYA&data=05%7C01%7C%7C35889715221b4e58f66308db1e32d7ba%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638136975934534623%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9Lggf3E8cYhkAKlcEOWV2HhcjVuKa67op3hU1B3HQus%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ctubbsii commented 1 year ago

Because there are several workarounds: using newer Java 11 to build, but with --release 8 if you need Java 8 as a target, or your workaround explicitly adding plexus-utils as a direct dependency, I don't see much reason to patch and release an older version.

sbernard31 commented 1 year ago

Because there are several workarounds: using newer Java 11 to build, but with --release 8 if you need Java 8 as a target, or your workaround explicitly adding plexus-utils as a direct dependency, I don't see much reason to patch and release an older version.

I was asking just in case. because even if there is several workaround, backporting the fix and also release a new bug_fix version for 1.6.x branch should not be so hard too. But no problem, if you think this doesn't worth it, I understand.

About using another JVM version than the targeting one (without using toolchain), we faced compatibility issue by the past and so we stop doing this. But maybe this is not true anymore, especially since addition of --release option.

Thx for you prompt answer and for pointing me to --release 8 option. :pray:

Additionally, if it's a must to stay where you are, then it would be best to stay on maven 3.8.x which is still supported.

I can not understand why this would be better than a new release or the workaround I currently used. :thinking: Anyway thx for feedback too :slightly_smiling_face:

hazendaz commented 1 year ago

@sbernard31 Its not longer an issue cross compiling these days to run into edge cases. However, the release option doesn't do anything with transient dependencies so you would additionally want enforcer plugin to make sure its binary compatible. Other than that its pretty solid. Speaking for myself and my daily life, we run something like 2k builds with more than 80% on jdk 17 but reality is varied older jdk usage from 8 to 11 and no issues doing so.

On maven suggestion, only indicating maven 3.9.0 isn't entirely necessary. That is for compatibility checks in moving to maven 4. It works well, work around needed in this particular case but maven is still releasing 3.8.x line. In fact, believe 3.8.8 along with 3.9.1 are going to voting likely later this week. So 3.8.x isn't dead yet. That was my only point in regards there. In my daily life we moved to 3.9.0 but we did hit some edge cases and even there worked around any we found.