forked from DevSrSouza/svg-to-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
144 lines (119 loc) · 3.82 KB
/
build.gradle.kts
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
plugins {
kotlin("jvm") version "2.0.0"
id("com.github.gmazzo.buildconfig") version "5.4.0"
id("maven-publish")
}
group = "br.com.devsrsouza"
version = "0.7.0"
description = "Converts SVG or Android Vector Drawable to Compose code."
val baseName = "svg2compose"
val r8: Configuration by configurations.creating
dependencies {
implementation("com.google.guava:guava:33.2.1-jre")
implementation("com.android.tools:sdk-common:31.5.1")
implementation("com.android.tools:common:31.5.1")
implementation("com.squareup:kotlinpoet:1.18.1")
implementation("org.ogce:xpp3:1.1.6")
implementation("com.github.ajalt.clikt:clikt:4.4.0")
testImplementation(kotlin("test-junit"))
r8("com.android.tools:r8:8.3.37")
}
tasks.test {
useJUnit()
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(11)
}
buildConfig {
buildConfigField("VERSION_NAME", version.toString())
buildConfigField("DESCRIPTION", description)
packageName = "br.com.devsrsouza.svg2compose"
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["kotlin"])
}
}
}
tasks.withType<Jar>().configureEach {
archiveBaseName = baseName
archiveVersion = version.toString()
manifest {
attributes["Main-Class"] = "br.com.devsrsouza.svg2compose.MainKt"
attributes["Implementation-Version"] = version.toString()
}
}
val fatJar by tasks.registering(Jar::class) {
dependsOn(configurations.runtimeClasspath)
dependsOn(tasks.jar)
from(sourceSets.main.map { it.output.classesDirs + it.output.resourcesDir })
from(configurations.runtimeClasspath.map { it.asFileTree.files.map(::zipTree) })
archiveClassifier = "fat"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
exclude(
"**/*.kotlin_metadata",
"**/*.kotlin_builtins",
"**/*.kotlin_module",
"**/module-info.class",
"assets/**",
"font_metrics.properties",
"META-INF/AL2.0",
"META-INF/DEPENDENCIES",
"META-INF/jdom-info.xml",
"META-INF/LGPL2.1",
"META-INF/maven/**",
"META-INF/native-image/**",
"META-INF/proguard/**",
"META-INF/*.version",
"META-INF/*.SF",
"META-INF/*.DSA",
"META-INF/*.RSA",
"**/*.proto",
"**/*.dex",
"**/LICENSE**",
"**/NOTICE**",
"r8-version.properties",
"migrateToAndroidx/*",
"xsd/catalog.xml",
)
}
val r8File = layout.buildDirectory.file("libs/$baseName-$version-r8.jar").map { it.asFile }
val rulesFile = project.file("src/main/proguard-rules.pro")
val r8Jar by tasks.registering(JavaExec::class) {
dependsOn(fatJar)
val fatJarFile = fatJar.get().archiveFile
inputs.file(fatJarFile)
inputs.file(rulesFile)
outputs.file(r8File)
classpath(r8)
mainClass = "com.android.tools.r8.R8"
args(
"--release",
"--classfile",
"--output", r8File.get().path,
"--pg-conf", rulesFile.path,
"--lib", System.getProperty("java.home"),
fatJarFile.get().toString(),
)
}
val binaryFile = layout.buildDirectory.file("libs/$baseName-$version-binary.jar").map { it.asFile }
val binaryJar by tasks.registering(Task::class) {
dependsOn(r8Jar)
val r8FileProvider = layout.file(r8File)
val binaryFileProvider = layout.file(binaryFile)
inputs.files(r8FileProvider)
outputs.file(binaryFileProvider)
doLast {
val r8File = r8FileProvider.get().asFile
val binaryFile = binaryFileProvider.get().asFile
binaryFile.parentFile.mkdirs()
binaryFile.delete()
binaryFile.writeText("#!/bin/sh\n\nexec java \$JAVA_OPTS -jar \$0 \"\$@\"\n\n")
binaryFile.appendBytes(r8File.readBytes())
binaryFile.setExecutable(true, false)
}
}
tasks.assemble {
dependsOn(binaryJar)
}