forked from careem/dependency-diff-tldr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
101 lines (81 loc) · 2.41 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.8.20"
id 'application'
}
application {
mainClass = 'com.careem.gradle.dependencies.DependencyTreeTldr'
}
configurations {
r8
}
dependencies {
implementation "com.github.ajalt.clikt:clikt:3.5.2"
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
r8 'com.android.tools:r8:8.0.40'
}
def fatJarProvider = tasks.register('fatJar', Jar) { task ->
task.dependsOn(configurations.named('runtimeClasspath'))
task.dependsOn(tasks.named('jar'))
task.classifier 'fat'
task.manifest {
attributes 'Main-Class': 'com.careem.gradle.dependencies.DependencyTreeTldr'
}
def sourceClasses = sourceSets.main.output.classesDirs
task.inputs.files(sourceClasses)
task.doFirst {
task.from files(sourceClasses)
task.from configurations.runtimeClasspath.asFileTree.files.collect { zipTree(it) }
task.exclude '**/*.kotlin_metadata'
task.exclude '**/*.kotlin_module'
task.exclude '**/*.kotlin_builtins'
task.exclude '**/module-info.class'
task.exclude 'META-INF/maven/**'
}
}
def r8File = new File("$buildDir/libs/$archivesBaseName-r8.jar")
def r8Jar = tasks.register('r8Jar', JavaExec) { task ->
task.dependsOn(configurations.named('runtimeClasspath'))
task.inputs.files(fatJarProvider.get().outputs.files)
task.outputs.file(r8File)
task.classpath(configurations.r8)
task.main = 'com.android.tools.r8.R8'
task.args = [
'--release',
'--classfile',
'--output', r8File.toString(),
'--pg-conf', 'src/main/rules.txt',
'--lib', System.properties['java.home'].toString()
]
doFirst {
task.args += fatJarProvider.get().archivePath
}
}
def binaryFile = new File("$buildDir/${archivesBaseName}.jar")
def binaryJar = tasks.register('binaryJar') { task ->
task.dependsOn(r8Jar)
task.inputs.file(r8File)
task.outputs.file(binaryFile)
task.doLast {
binaryFile.getParentFile().mkdirs()
binaryFile.delete()
binaryFile << "#!/bin/sh\n\nexec java \$JAVA_OPTS -jar \$0 \"\$@\"\n\n"
r8File.withInputStream { binaryFile.append it }
binaryFile.setExecutable true, false
}
}
tasks.named('assemble').configure { task ->
task.dependsOn(binaryJar)
}
artifacts {
archives file: binaryFile, name: 'binary', type: 'jar', builtBy: binaryJar, classifier: 'binary'
}
repositories {
mavenCentral()
google()
}