Shading a Plugin Dependency and removing it from the pom

Hello

I’m writing a Gradle plugin that depends on another module in the project. However this module isn’t published to any repository, so I shade it and deploy the shaded jar (with shadow). The problem, however is that the dependency stays in the pom and module files created by the maven-publish plugin (and I presume are there behind the scenes on the Gradle Plugin Portal).

Is there an easy way out here? I managed to remove the dependencies from the pom via
withDependencies {
it.clear()
}
but that doesn’t remove them from the module file, so my error persists.

Is there any solution here?

Thanks

You could put the shaded dependency in a different configuration. Eg:

configurations {
   shademe
} 
dependencies {
   shademe 'foo:shademe:1.0'
   compile files({tasks.shadowJar})
}

// shadow syntax might be slightly different to this but you get the idea 
task shadowJar(type: ShadowJar) {
   from configurations.shademe
   into "$buildDir/shaded.jar"
} 

Yeah, that could work, thanks. I have a few other dependencies (Gson and Guava). Should I shade these too, or have them resolved via Maven Central?

Typically you will shade a jar because you have a good reason for this jar NOT to participate in dependency resolution. So you manipulate the classes to move them to a new package then include the repackaged jars inside your own jar. This means its possible for two or more versions of the classes on the classpath (since packages are different). I’ve often seen this with ASM.

Unless you’ve got a good reason why these jar(s) should NOT be participating in dependency resolution I don’t believe you should be shading them at all

I see. Well, as I mentioned before, one of the jars isn’t in any repository, so needs to be shaded, but I’ll leave the others.

Thank you for the help!

Perhaps you can just unzip the jar and include the classes inside your plugin jar

Something like

configurations {
   unzipme { transitive = false } 
   compileOnly { extendsFrom unzipme } 
} 
dependencies {
   unzipme 'foo:bar:1.0' 
}
processResources {
   from zipTree(configurations.unzipme.singleFile)
}