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

Consider shading the JGit dependency in Grade plugin #587

Open
netvl opened this issue May 30, 2020 · 8 comments · May be fixed by #1991
Open

Consider shading the JGit dependency in Grade plugin #587

netvl opened this issue May 30, 2020 · 8 comments · May be fixed by #1991

Comments

@netvl
Copy link

netvl commented May 30, 2020

Summary

In Gradle, all plugins share the same classpath. This makes it very hard, if not impossible, to use plugins which depend on different incompatible versions of the same library. This is the case with Spotless and GitPublish:

  1. Spotless depends on 5.7.0.202003110725-r
  2. GitPublish depends on the "latest release" version, which for the latest version of the plugin itself is 5.6.0.201912101111-r

Downgrading the JGit dependency in Spotless, I believe, is not an option, but maybe you could consider shading this dependency, building it into the Gradle plugin JAR file? I believe that the official Gradle guidelines recommend minimizing the number of external dependencies, and shading is one of the ways to mitigate issues like this one.

Gradle version

Happens with any Gradle version, including the latest one, 6.4.1

Spotless version

4.0.1

Operating system and version

Probably not relevant, but macOS 10.15.3

Spotless configuration

Having something as simple as

spotless {
    scala {
        scalafmt("2.3.2").configFile(layout.projectDirectory.file(".scalafmt.conf"))
    }
}

in the build configuration will reproduce the issue,.

Console errors

In all my test cases any Spotless tasks don't cause errors; exceptions can be observed when the GitPublish plugin is used, and they are generic class linkage errors which happen when binary incompatible libraries with the same class names are present in the one classpath.

@nedtwigg
Copy link
Member

Hm, I thought Gradle had some classloader magic to isolate the plugins a bit, but such magic is always very fragile, so I don't doubt you!

The gradle plugin consists of three artifacts, lib with no dependencies, lib-extra with JGit and a few others, and then plugin-gradle which needs both of those.

I think it's good for lib to be pristine (allows people to build their own stuff and integrate easily), but I don't see any problem with shading everything else, including lib-extra, into plugin-gradle. Unless other contributors raise objections, I'd be happy to merge and release a PR that accomplished that.

@jbduncan
Copy link
Member

I'm not personally using Spotless's internals like lib or lib-extra at this time, so I'm happy for any of the dependencies to be shaded into plugin-gradle. 👍

@nedtwigg
Copy link
Member

As a workaround, you can try futzing with something like this:

buildscript {
  configurations.classpath {
    resolutionStrategy {
      force 'org.eclipse.jgit:org.eclipse.jgit:5.7.0.202003110725-r'
    }
  }
}

@michaelruocco
Copy link

The workaround listed above works fine for me, any plans for a more permanent fix?

@nedtwigg
Copy link
Member

The permanent fix is to shade everything except lib into plugin-gradle. It's very low on my todo list, but happy to merge and release a PR for it.

@michaelruocco
Copy link

That is fair, it's not a huge issue, especially with the work around you have provided. I'll try and see if I can raise a PR if I can find the time to familiarise myself with the code base. Thanks.

@nedtwigg
Copy link
Member

[editor's note: deleted a few off-topic comments to keep this issue focused on jgit shading and its workaround]

@netvl
Copy link
Author

netvl commented Apr 1, 2021

FWIW, I'm not quite sure how resolutionStrategy thing is a workaround - it will force another version, sure, but the issue with different plugins depending on different, binary incompatible versions of the same library remains: either spotless won't work, or gradle-git-publish (in this case).

rickard-von-essen added a commit to rickard-von-essen/spotless that referenced this issue Jan 10, 2024
This builds a shadow jar with all dependencies bundled in the plugin and relocates
most dependencies under shadow. This will fix issues where other Gradle plugins uses
incopatible versions of the same dependencis.

Fixes diffplug#587
rickard-von-essen added a commit to rickard-von-essen/spotless that referenced this issue Jan 10, 2024
This builds a shadow jar with all dependencies bundled in the plugin and relocates
most dependencies under shadow. This will fix issues where other Gradle plugins uses
incompatible versions of the same dependencies.

Fixes diffplug#587
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants