将依赖的jar包inlining到另外一个jar包的ant插件 javajarjarant
程序员文章站
2022-05-20 08:36:58
...
https://code.google.com/p/jarjar/
Jar Jar Links is a utility that makes it easy to repackage Java libraries and embed them into your own distribution. This is useful for two reasons:
- You can easily ship a single jar file with no external dependencies.
- You can avoid problems where your library depends on a specific version of a library, which may conflict with the dependencies of another library.
spring中https://github.com/spring-projects/spring-framework/blob/3.2.x/build.gradle构建spring-core包,将asm和cglib包inling到spring-core包中。
task asmRepackJar(type: Jar) { repackJar ->
repackJar.baseName = "spring-asm-repack"
repackJar.version = asmVersion
doLast() {
project.ant {
taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask",
classpath: configurations.jarjar.asPath
jarjar(destfile: repackJar.archivePath) {
configurations.asm.each { originalJar ->
zipfileset(src: originalJar)
}
rule(pattern: "org.objectweb.asm.**", result: "org.springframework.asm.@1")
}
}
}
}
task cglibRepackJar(type: Jar) { repackJar ->
repackJar.baseName = "spring-cglib-repack"
repackJar.version = cglibVersion
doLast() {
project.ant {
taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask",
classpath: configurations.jarjar.asPath
jarjar(destfile: repackJar.archivePath) {
configurations.cglib.each { originalJar ->
zipfileset(src: originalJar)
}
// repackage net.sf.cglib => org.springframework.cglib
rule(pattern: "net.sf.cglib.**", result: "org.springframework.cglib.@1")
// as mentioned above, transform cglib"s internal asm dependencies from
// org.objectweb.asm => org.springframework.asm. Doing this counts on the
// the fact that Spring and cglib depend on the same version of asm!
rule(pattern: "org.objectweb.asm.**", result: "org.springframework.asm.@1")
}
}
}
}