Skip to content

Commit

Permalink
gradle, config, shadowJar
Browse files Browse the repository at this point in the history
  • Loading branch information
binarynoise committed Sep 12, 2023
1 parent 8651037 commit 4d7e8e1
Show file tree
Hide file tree
Showing 19 changed files with 565 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* text=auto
MANIFEST text eol=crlf
*.bat text eol=crlf
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/build/
/.gradle/
/.idea/*
!/.idea/artifacts
!/.idea/libraries
!/.idea/kotlinc.xml
!/.idea/modules.xml
!/.idea/vcs.xml
/.idea
/application.conf
*.iml
13 changes: 0 additions & 13 deletions .idea/artifacts/dns_benchmark_jar.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

26 changes: 0 additions & 26 deletions .idea/libraries/KotlinJavaRuntime.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

88 changes: 88 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
kotlin("jvm") version "1.9.10"
kotlin("plugin.serialization") version "1.9.10"
}

val javaVersion = JavaVersion.VERSION_1_8
val javaVersionNumber = javaVersion.name.substringAfter('_').replace('_', '.')
val javaVersionMajor = javaVersion.name.substringAfterLast('_')

val r8: Configuration by configurations.creating
dependencies {
implementation(kotlin("serialization"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:1.6.0")
r8("com.android.tools:r8:+")
}


tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = javaVersionNumber
}

tasks.withType<AbstractCompile> {
sourceCompatibility = javaVersionNumber
targetCompatibility = javaVersionNumber
}

tasks.withType<Jar> {
manifest {
attributes(mapOf("Main-Class" to "MainKt"))
}
}

tasks.withType<ShadowJar> {
archiveClassifier.set("shadow")
mergeServiceFiles()
minimize()
exclude("**/*.kotlin_*")
}

tasks {
assemble {
dependsOn(shadowJarMinified)
}
}

val shadowJarMinified = tasks.register<JavaExec>("shadowJarMinified") {
dependsOn(configurations.runtimeClasspath)

val proguardRules = file("src/main/proguard-rules.pro")
inputs.files(tasks.shadowJar.get().outputs.files, proguardRules)

val r8File = layout.buildDirectory.file("libs/${base.archivesName.get()}-shadow-minified.jar").get().asFile
outputs.file(r8File)

classpath(r8)

mainClass.set("com.android.tools.r8.R8")
val javaHome = File(ProcessHandle.current().info().command().get()).parentFile.parentFile.canonicalPath

val args = mutableListOf(
//"--debug",
"--classfile",
"--output",
r8File.toString(),
"--pg-conf",
proguardRules.toString(),
"--lib",
javaHome,
)
args.add(tasks.shadowJar.get().outputs.files.joinToString(" "))

this.args = args

doFirst {
val javaHomeVersion = Runtime.getRuntime().exec("$javaHome/bin/java -version").run {
(inputStream.bufferedReader().readText() + errorStream.bufferedReader().readText()).split('"')[1]
}
check(JavaVersion.toVersion(javaHomeVersion).isCompatibleWith(javaVersion)) {
"Incompatible Java Versions: compile-target $javaVersionNumber, r8 runtime $javaHomeVersion (needs to be as new or newer)"
}

check(proguardRules.exists()) { "$proguardRules doesn't exist" }
}
}
15 changes: 0 additions & 15 deletions dns-benchmark.iml

This file was deleted.

3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kotlin.code.style=official
org.gradle.caching=true
org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 4d7e8e1

Please sign in to comment.