Skip to content

Commit 2b6abb7

Browse files
committed
Add proguard
1 parent 2ab70a9 commit 2b6abb7

File tree

3 files changed

+142
-316
lines changed

3 files changed

+142
-316
lines changed

Essential/build.gradle.kts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies {
2121
implementation(libs.kaml)
2222
implementation(libs.jbcrypt)
2323

24+
implementation(libs.proguard)
25+
2426
testImplementation(kotlin("test"))
2527
testImplementation(libs.bundles.game.test)
2628
testImplementation(libs.bundles.kotlinxEcosystem)
@@ -29,3 +31,52 @@ dependencies {
2931
testImplementation(libs.bundles.r2dbc.drivers)
3032
testImplementation(libs.jbcrypt)
3133
}
34+
35+
tasks.register<JavaExec>("proguardJar") {
36+
val shadowJarFile = tasks.shadowJar.get().archiveFile.get().asFile
37+
val outputFile = File(buildDir, "libs/${project.name}-proguard.jar")
38+
39+
// Make sure the output directory exists
40+
doFirst {
41+
outputFile.parentFile.mkdirs()
42+
}
43+
44+
// Configure the JavaExec task
45+
mainClass.set("proguard.ProGuard")
46+
classpath = configurations.runtimeClasspath.get()
47+
48+
// ProGuard arguments
49+
val argsList = mutableListOf(
50+
"-injars", shadowJarFile.absolutePath,
51+
"-outjars", outputFile.absolutePath,
52+
"-printmapping", "${buildDir}/proguard/mapping.txt",
53+
"-printseeds", "${buildDir}/proguard/seeds.txt",
54+
"-printusage", "${buildDir}/proguard/usage.txt",
55+
"@${rootProject.projectDir}/proguard-rules.pro"
56+
)
57+
58+
// Provide ALL compile+runtime classpath entries as library jars for analysis only
59+
// (exclude the fat shadow jar which is already passed as -injars)
60+
val runtimeFiles = configurations.runtimeClasspath.get().files
61+
val compileFiles = configurations.compileClasspath.get().files
62+
val allLibs = (runtimeFiles + compileFiles)
63+
.asSequence()
64+
.filter { it.exists() && it != shadowJarFile }
65+
.distinctBy { it.absolutePath }
66+
.toList()
67+
allLibs.forEach { file ->
68+
argsList.addAll(listOf("-libraryjars", file.absolutePath))
69+
}
70+
71+
args = argsList
72+
doFirst {
73+
File("${buildDir}/proguard").mkdirs()
74+
}
75+
}
76+
77+
tasks.test {
78+
testLogging {
79+
events("failed")
80+
exceptionFormat = TestExceptionFormat.SHORT
81+
}
82+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ logback = "1.5.16"
1919
dataFaker = "2.5.3"
2020
mockito = "5.20.0"
2121
jts = "1.20.0"
22-
h2 = "2.3.232"
23-
sqlite = "3.50.3.0"
24-
r2dbcH2 = "1.0.0.RELEASE"
22+
proguard = "7.8.1"
23+
2524
lingua = "1.2.2"
2625
discord = "5.6.1"
2726
ktor = "3.3.1"

0 commit comments

Comments
 (0)