Last active
October 24, 2018 21:08
-
-
Save cholick/7177513 to your computer and use it in GitHub Desktop.
Using Gradle & jarjar to repackage and embed incompatible transitive dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'groovy' | |
repositories { | |
mavenCentral() | |
} | |
configurations { | |
patch | |
[compile, testCompile]*.exclude module: 'jersey-server' | |
} | |
dependencies { | |
compile('com.yammer.dropwizard:dropwizard-core:0.6.2') | |
compile('com.sun.jersey:jersey-client:1.17.1') | |
compile files('lib/jersey-server-1.17.1.patched.jar') | |
compile('org.codehaus.groovy:groovy-all:2.1.3') | |
compile('com.google.inject:guice:4.0-beta') | |
compile('org.pegdown:pegdown:1.4.1') | |
patch('com.sun.jersey:jersey-server:1.17.1') | |
patch('asm:asm:3.1') | |
patch('com.googlecode.jarjar:jarjar:1.3') | |
} | |
project.ext.set("shouldBuildPatch", { !new File('lib/jersey-server-1.17.1.patched.jar').exists() }) | |
task downloadPatchLibs(type: Copy) { | |
into('lib') | |
from(configurations.patch) | |
exclude('jarjar*') | |
duplicatesStrategy(DuplicatesStrategy.EXCLUDE) | |
} | |
downloadPatchLibs.doFirst { | |
if(!shouldBuildPatch()) { throw new StopExecutionException() } | |
} | |
task applyPatch(dependsOn: 'downloadPatchLibs') << { | |
if (shouldBuildPatch()) { | |
project.ant { | |
taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.patch.asPath | |
jarjar(jarfile: 'lib/jersey-server-1.17.1.patched.jar', filesetmanifest: "merge") { | |
zipfileset(src: 'lib/jersey-server-1.17.1.jar') | |
zipfileset(src: 'lib/asm-3.1.jar') | |
rule pattern: "org.objectweb.asm.**", result: "org.objectweb.asm3.@1" | |
} | |
} | |
} | |
} | |
task cleanupDownloadPatchLibs(type: Delete, dependsOn: 'applyPatch') { | |
delete 'lib/jersey-server-1.17.1.jar' | |
delete 'lib/asm-3.1.jar' | |
} | |
compileGroovy.dependsOn(cleanupDownloadPatchLibs) | |
task cleanPatch(type: Delete) { | |
delete 'lib' | |
} | |
clean.dependsOn(cleanPatch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment