-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.gradle
123 lines (100 loc) · 2.93 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
buildscript {
dependencies {
classpath libs.kotlin.gradle.plugin
}
}
apply plugin: 'org.jetbrains.kotlin.jvm'
configurations {
r8
}
dependencies {
testImplementation libs.junit
testImplementation libs.assertk
r8 libs.r8
}
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.withType(KotlinJvmCompile).configureEach {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
freeCompilerArgs.addAll(
'-Xno-call-assertions',
'-Xno-param-assertions',
'-Xno-receiver-assertions',
)
}
}
def fatJarProvider = tasks.register('fatJar', Jar) { task ->
task.dependsOn(configurations.named('runtimeClasspath'))
task.dependsOn(tasks.named('jar'))
task.archiveClassifier = 'fat'
task.manifest {
attributes 'Main-Class': 'com.jakewharton.gradle.dependencies.DependencyTreeDiff'
}
def sourceClasses = sourceSets.main.output.classesDirs
task.inputs.files(sourceClasses)
task.from files(sourceClasses)
task.from configurations.named('runtimeClasspath').map {
it.asFileTree.files.collect { it.isDirectory() ? it : 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 = layout.buildDirectory.file("libs/${base.archivesName.get()}-r8.jar").get().asFile
def rulesFile = project.file("src/main/rules.txt")
def r8Jar = tasks.register('r8Jar', JavaExec) { task ->
def fatJarFile = fatJarProvider.get().archiveFile
task.inputs.file(fatJarFile)
task.inputs.file(rulesFile)
task.outputs.file(r8File)
// R8 uses the executing JDK to determine the classfile target.
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
vendor = JvmVendorSpec.AZUL
}
task.classpath(configurations.r8)
task.mainClass = 'com.android.tools.r8.R8'
task.args = [
'--release',
'--classfile',
'--output', r8File.path,
'--pg-conf', rulesFile.path,
'--lib', System.properties['java.home'].toString(),
fatJarFile.get().asFile.path
]
}
def binaryFile = layout.buildDirectory.file("${base.archivesName.get()}.jar").get().asFile
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'
}
buildscript {
repositories {
mavenCentral()
}
}
repositories {
mavenCentral()
google()
}