0

I'm looking for some automatic/simple way to exclude all dependencies from the final jar if they are already contained in any of compile-only depenceny which isn't present in the final jar but is loaded externally. I'm using kotlin DSL for gradle configuration.

my current jar configuration:

withType<Jar> { duplicatesStrategy = DuplicatesStrategy.EXCLUDE archiveClassifier.set("core") from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) exclude( "kotlin/**" ) } 

For example I implement jackson yaml format which uses snake YAML as a dependency. However snake YAML is also present in one compileOnly dependency and shouldn't be contained in the final JAR.

If I understand it correctly runtimeClasspath contains only implementation dependencies, but also all of their dependencies, which is the problem

1 Answer 1

1

you can have a custom task to create the list of jars you want to package, below snippet show the runtime-compileonly

task runCP() { def runList = configurations.runtimeClasspath.asList() def compileOnlyList = configurations.compileOnly.asList() println(runList.join("\n")) println("----") println(compileOnlyList.join("\n")) println("====") println(runList.size() + " | " + runList.removeAll(compileOnlyList) + " | " + runList.size()) println(runList.join("\n")) } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.