-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite build to use shade plugin instead of jarjar
- Loading branch information
1 parent
847a01b
commit 5a1c67f
Showing
19 changed files
with
288 additions
and
630 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,27 @@ | ||
import org.anarres.gradle.plugin.jarjar.JarjarTask | ||
|
||
// this is a hack because of how we replace jarjar'ed JAR need to manually supply dependencies to POM | ||
// Declare all dependencies in this map and not with the dependencies block! | ||
def deps = [ | ||
compile: [ | ||
project(":inject") | ||
] | ||
] | ||
|
||
ext.extraPomInfo = { | ||
delegate.dependencies { | ||
for(entry in deps) { | ||
def scope = entry.key | ||
def values = entry.value | ||
for(dep in values) { | ||
delegate.dependency { | ||
def groupId | ||
def artifactId | ||
def artifactVersion | ||
|
||
if(dep instanceof Project) { | ||
groupId = projectGroupId | ||
artifactId = dep.name | ||
artifactVersion = version | ||
} | ||
else { | ||
|
||
groupId = dep.group | ||
artifactId = dep.name | ||
artifactVersion = dep.version | ||
} | ||
|
||
delegate.groupId groupId | ||
delegate.artifactId artifactId | ||
delegate.version artifactVersion | ||
delegate.scope scope | ||
} | ||
} | ||
} | ||
} | ||
} | ||
apply plugin: 'com.github.johnrengelman.plugin-shadow' | ||
|
||
dependencies { | ||
for(entry in deps) { | ||
def scope = entry.key | ||
for(dep in entry.value) { | ||
"$scope"(dep) | ||
} | ||
} | ||
shadowCompile project(":inject") | ||
compile project(":inject") | ||
} | ||
|
||
shadowJar { | ||
dependencies { | ||
exclude(project(":inject")) | ||
exclude(project(":core")) | ||
exclude(dependency(group:'org.slf4j',name:'slf4j-api',version:slf4jVersion)) | ||
exclude(dependency(group: 'javax.inject', name: 'javax.inject', version: '1')) | ||
exclude(dependency('org.ow2.asm:.*:.*')) | ||
exclude(dependency('org.reactivestreams:.*:.*')) | ||
exclude(dependency('com.google.code.findbugs:.*:.*')) | ||
exclude(dependency('com.github.ben-manes.caffeine:.*:.*')) | ||
} | ||
|
||
relocate "org.objectweb.asm", "io.micronaut.asm" | ||
relocate "com.github.benmanes.caffeine", "io.micronaut.caffeine" | ||
|
||
def targetDir = new File(project.buildDir, "jarjar") | ||
def targetFile = new File(targetDir, "asm.jar") | ||
def jarjarTask = task("jarjarTask", type: JarjarTask) { | ||
from(jar.outputs.files) | ||
classRename "org.objectweb.asm.**", "io.micronaut.asm.@1" | ||
destinationDir = targetDir | ||
destinationName = targetFile.name | ||
} | ||
|
||
def jarjarOutputs = task("jarjarOutputs").doLast { | ||
copy { | ||
from zipTree(jarjarTask.outputs.files.first()) | ||
into(targetDir) | ||
} | ||
delete(jarjarTask.outputs.files) | ||
} | ||
jarjarOutputs.dependsOn(jarjarTask) | ||
task("rejar", type:Jar, dependsOn: jarjarOutputs) { | ||
from(targetDir) | ||
archiveName = "rejar.jar" | ||
} | ||
tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) { t -> | ||
t.enabled = false | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,27 @@ | ||
import org.anarres.gradle.plugin.jarjar.JarjarTask | ||
apply plugin: 'com.github.johnrengelman.plugin-shadow' | ||
|
||
// this is a hack because of how we replace jarjar'ed JAR need to manually supply dependencies to POM | ||
// Declare all dependencies in this map and not with the dependencies block! | ||
def deps = [ | ||
compile: [ | ||
[group:'org.reactivestreams', name:'reactive-streams', version:'1.0.1'], | ||
[group:'com.google.code.findbugs',name:'jsr305',version:'3.0.2'] | ||
] | ||
] | ||
|
||
ext.extraPomInfo = { | ||
delegate.dependencies { | ||
for(entry in deps) { | ||
def scope = entry.key | ||
def values = entry.value | ||
for(dep in values) { | ||
delegate.dependency { | ||
def groupId | ||
def artifactId | ||
def artifactVersion | ||
|
||
if(dep instanceof Project) { | ||
groupId = projectGroupId | ||
artifactId = dep.name | ||
artifactVersion = version | ||
} | ||
else { | ||
|
||
groupId = dep.group | ||
artifactId = dep.name | ||
artifactVersion = dep.version | ||
} | ||
|
||
delegate.groupId groupId | ||
delegate.artifactId artifactId | ||
delegate.version artifactVersion | ||
delegate.scope scope | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
dependencies { | ||
for(entry in deps) { | ||
def scope = entry.key | ||
for(dep in entry.value) { | ||
"$scope"(dep) | ||
} | ||
} | ||
} | ||
|
||
|
||
// ########################## | ||
// JARJAR handling | ||
def targetDir = new File(project.buildDir, "jarjar") | ||
|
||
// ########################## | ||
// ASM JARJAR handling | ||
def asmDependencies = [ | ||
[group:'org.ow2.asm', name: 'asm', version:asmVersion], | ||
[group:'org.ow2.asm', name: 'asm-commons', version:asmVersion], | ||
[group:'org.ow2.asm', name: 'asm-tree', version:asmVersion] | ||
|
||
] | ||
Task taskAsmDownload = buildDownloadTask("asm", asmDependencies, asmVersion) | ||
buildJarJarTask(targetDir, taskAsmDownload, "asm", ["org.objectweb.asm": "io.micronaut.asm"]) | ||
|
||
|
||
// ########################## | ||
// Caffeine JARJAR handling | ||
def caffeineDependencies = [ | ||
[group:'com.github.ben-manes.caffeine',name:'caffeine', version: caffeineVersion], | ||
|
||
] | ||
Task caffeineDownloadTask = buildDownloadTask("caffeine", caffeineDependencies, caffeineVersion) | ||
buildJarJarTask(targetDir, caffeineDownloadTask, "caffeine", ["com.github.benmanes.caffeine": "io.micronaut.caffeine"]) | ||
|
||
// ########################## | ||
// Project JARJAR handling | ||
def jarjarOutputJar = new File(targetDir, "jarjar-output.jar") | ||
def jarjarTask = task("jarjarTask", type: JarjarTask) { | ||
from(project.files(jar.archivePath)) | ||
classRename "org.objectweb.asm.**", "io.micronaut.asm.@1" | ||
classRename "com.github.benmanes.caffeine.**", "io.micronaut.caffeine.@1" | ||
destinationDir = targetDir | ||
destinationName = jarjarOutputJar.name | ||
} | ||
jarjarTask.dependsOn(jar) | ||
|
||
def jarjarOutputs = task("jarjarOutputs").doLast { | ||
copy { | ||
from zipTree(jarjarTask.destinationPath) | ||
into(targetDir) | ||
shadowJar { | ||
dependencies { | ||
exclude(dependency(group:'org.reactivestreams', name:'reactive-streams', version:'1.0.1')) | ||
exclude(dependency(group:'com.google.code.findbugs',name:'jsr305',version:'3.0.2')) | ||
} | ||
delete(jarjarTask.destinationPath) | ||
relocate "org.objectweb.asm", "io.micronaut.asm" | ||
relocate "com.github.benmanes.caffeine", "io.micronaut.caffeine" | ||
} | ||
|
||
jarjarOutputs.dependsOn(jarjarTask) | ||
task("rejar", type:Jar, dependsOn: jarjarOutputs) { | ||
from(targetDir) | ||
archiveName = "rejar.jar" | ||
tasks.withType(com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) { t -> | ||
t.enabled = false | ||
} | ||
|
||
protected Task buildDownloadTask(String name, List dependencies, String version) { | ||
Task taskAsmDownload = task("${name}Download") | ||
File downloadDir = new File(project.buildDir, "artifact-download") | ||
File targetDir = new File(downloadDir, name) | ||
taskAsmDownload.doLast { | ||
URI mavenCentralURL = repositories.find(){ | ||
println it.name | ||
it.name == 'maven' | ||
}.url | ||
ant.mkdir(dir:targetDir) | ||
for(dep in dependencies) { | ||
|
||
ant.get(src:"${mavenCentralURL}/${dep.group.replace('.','/')}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar", dest: targetDir) | ||
} | ||
} | ||
taskAsmDownload.inputs.properties(version: version) | ||
taskAsmDownload.outputs.dir(targetDir) | ||
|
||
return taskAsmDownload | ||
} | ||
|
||
protected void buildJarJarTask(File targetDir, Task jars, String name, Map mappings) { | ||
File targetJarFile = new File(targetDir, "${name}.jar") | ||
Task jarjarTask = task("${name}jarjarTask", type: JarjarTask) { | ||
from(fileTree(jars.outputs.files.first())) | ||
for(entry in mappings) { | ||
classRename "${entry.key}.**", "${entry.value}.@1" | ||
} | ||
destinationDir = targetDir | ||
destinationName = targetJarFile.name | ||
} | ||
jarjarTask.inputs.files(jars) | ||
jarjarTask.outputs.files(targetJarFile) | ||
|
||
Task jarjarOutput = task("${name}jarjarOutput") | ||
jarjarOutput.doLast { | ||
copy { | ||
from(zipTree(targetJarFile)) { | ||
for(v in mappings.values()) | ||
include "${v.replace('.','/')}/**" | ||
} | ||
into(new File(project.buildDir, "classes/java/main")) | ||
} | ||
} | ||
jarjarOutput.dependsOn(jarjarTask) | ||
classes { | ||
dependsOn(jarjarOutput) | ||
} | ||
dependencies { | ||
shadowCompile group:'org.reactivestreams', name:'reactive-streams', version:'1.0.1' | ||
shadowCompile group:'com.google.code.findbugs',name:'jsr305',version:'3.0.2' | ||
|
||
compile group:'org.reactivestreams', name:'reactive-streams', version:'1.0.1' | ||
compile group:'com.google.code.findbugs',name:'jsr305',version:'3.0.2' | ||
compile group:'org.ow2.asm', name: 'asm', version:asmVersion | ||
compile group:'org.ow2.asm', name: 'asm-commons', version:asmVersion | ||
compile group:'org.ow2.asm', name: 'asm-tree', version:asmVersion | ||
compile group:'com.github.ben-manes.caffeine',name:'caffeine', version: caffeineVersion | ||
} |
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
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
Oops, something went wrong.