skuzzle / restrict-imports-enforcer-rule

Gradle plugin & Maven Enforcer rule that restricts usage of unwanted imports in Java, Kotlin and Groovy source files.
MIT License
75 stars 12 forks source link

rule failed with NoSuchMethodError #20

Closed SimY4 closed 6 years ago

SimY4 commented 6 years ago

After updating to 0.12.0 enforcer plugin starts failing with:

Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce (enforce-restrict-imports) on project id-hydra-transformer: Execution enforce-restrict-imports of goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce: java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;

I'm using latest enforer plugin version and latest maven version.

UPD: rolled back to 0.10.0 - the last version without this error.

UPD2: turn out the problem here lies in the fact that maven enforcer plugin shares single classloader between all enforcer rules. and guava historically has an issue of conflicting class definitions with google-collections dependency. The problem can be reproduced if you have another rule with uses google collections internally.

UPD3: google-collections is a dependency for plexus-container-default which is part of some enforcer rules prerequisites

skuzzle commented 6 years ago

It is well possible that I've adjusted the guava version in one of the last plugin releases. Can you supply a minimal example configuration so I can reproduce the issue? Resolving this seems a little tricky for now:

  1. I could downgrade to an older version of guava. This would imply that I have to build and maintain some kind of compatibility table because I have to keep my guava version in synch with the guava version used by the supported maven versions.
  2. I could remove the questionable line which using copyOf. It is not a mission critical statement but only used to defensively copy a list to be held in an immutable POJO.
  3. I could use maven shade plugin to burn the guava libs into the plugin with a different package name

For now I'm not very happy with either of the solutions.

SimY4 commented 6 years ago

Hi @skuzzle

Thanks for looking into this problem.

I've put a few updates on why I think this problem is happening. In short. guava is conflicting with google-collection dependency which is a prerequisite for various other rules.

skuzzle commented 6 years ago

In current snapshot I've removed the copyOf call which likely caused your problem. Would you mind trying your configuration with the current snapshot (0.13.0-SNAPSHOT)?

SimY4 commented 6 years ago

@skuzzle I tested the latest version. Looks like the issue is gone.

Again, thanks for looking into this.

skuzzle commented 6 years ago

Released as 0.13.0