Gradle shadow plugin packages are also all the “provided” dependencies, which should not be in this case

I want to have one thick jar, but without the dependencies provided. Therefore, I use the following two plugins:

and create the build.gradle file as follows:

apply plugin: 'nebula.provided-base' apply plugin: 'com.github.johnrengelman.shadow' archivesBaseName = 'range-cache-drivers' group = 'com.engine' version = '0.302-SNAPSHOT' buildDir = 'target' sourceCompatibility = 1.8 targetCompatibility = 1.8 dependencies { provided project(':rangeCache') // CSV, TSV, Fixe width compile deps.univocityParsers // MongoDB compile deps.mongo // Cassandra compile deps.cassandradx compile deps.cassandraSnappy compile deps.cassandraLZ4 } 

But when I run gradle shadowJar , I still have all rangeCache classes in my thick jar. How can I exclude the provided dependencies from my thick jar?

EDIT 1: This also does not work, transient dependencies are still copied to the fat jar.

 shadowJar { dependencies { exclude(project(':rangeCache')) } } 

EDIT 2: Based on Stanislav's answer, I did the following for proper operation:

 configurations { shadow compile.extendsFrom provided provided.extendsFrom shadow } dependencies { provided project(':rangeCache') // CSV, TSV, Fixe width shadow deps.univocityParsers // MongoDB shadow deps.mongo // Cassandra shadow deps.cassandradx shadow deps.cassandraSnappy shadow deps.cassandraLZ4 testCompile deps.junit } import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar task fatJar(type: ShadowJar) { configurations = [project.configurations.shadow] from(project.sourceSets.main.output) } 
+5
source share
1 answer

Check out this article on Shadow Jar Dependency Exclusion.

Soon, according to this article, simply excluding dependency from shadowJar dependencies shadowJar not enough to exclude its transitive dependencies, as you already mentioned. The solution to this is to change the run-time configuration to eliminate some dependency from it, for example:

 configurations { runtime.exclude %what you need to exclude% } 

Hope this can be helpful.

0
source

Source: https://habr.com/ru/post/1235209/


All Articles