Want to remove specific jars from Gradle fat jar
My current build.gradle file looks like below.
repositories {
flatDir {
dirs 'lib'
}
maven {
mavenCentral()
}
dependencies {
compile "commons-logging:commons-logging:1.0.4",
"org.apache.httpcomponents:httpclient:4.4",
"org.apache.httpcomponents:httpcore:4.4",
"com.fasterxml.jackson.core:jackson-annotations:2.5.1",
"joda-time:joda-time:2.7",
compile files('../lib/abc.jar')
}
jar {
manifest{
attributes ("Version" : project.version, "${parent.manifestSectionName}")
attributes ("Name" : project.name, "${parent.manifestSectionName}")
}
from {
configurations.runtime.filter( {! (it.name =~ /abc.*\.jar/ )}).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
So, as you can see, I removed abc.jar at runtime, but I also want to remove a few jars. In short, I want the jar to be free of cans and should be eliminated. So how can I achieve this?
+3
source to share
1 answer
The following example might help you. You need to add a new config - it extends compilation by default, so it will be available at development time, but not included in the final jar - like joda in the example below.
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
lol
}
dependencies {
compile "commons-logging:commons-logging:1.0.4",
"org.apache.httpcomponents:httpclient:4.4",
"org.apache.httpcomponents:httpcore:4.4",
"com.fasterxml.jackson.core:jackson-annotations:2.5.1"
lol "joda-time:joda-time:2.7"
}
jar {
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
0
source to share