Skip to content

Instantly share code, notes, and snippets.

@anatawa12
Created March 21, 2021 06:02
Show Gist options
  • Save anatawa12/a42300df55a655327a4b67b0c9bdde80 to your computer and use it in GitHub Desktop.
Save anatawa12/a42300df55a655327a4b67b0c9bdde80 to your computer and use it in GitHub Desktop.
the example script to shadow and relocate kotlin for ForgeGradle
import com.anatawa12.javaStabGen.gradle.GenerateJavaStab
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "<version>"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
val shade by configurations.creating
configurations.compile.get().extendsFrom(shade)
dependencies {
shade(kotlin("stdlib-jdk7"))
}
val jar by tasks.getting(Jar::class) {
shade.forEach { dep ->
from(project.zipTree(dep)) {
exclude("META-INF", "META-INF/**")
exclude("LICENSE.txt")
}
}
}
val shadowModJar by tasks.creating(ShadowJar::class) {
dependsOn(tasks.reobfJar.get())
relocate("kotlin.", "your.mod.package.kotlin.")
from(provider { zipTree(tasks.jar.get().archiveFile) })
destinationDirectory.set(buildDir.resolve("shadowing"))
archiveVersion.set("")
manifest.from(provider {
zipTree(tasks.jar.get().archiveFile)
.matching { include("META-INF/MANIFEST.MF") }
.files.first()
})
}
val copyShadowedJar by tasks.creating {
dependsOn(shadowModJar)
doLast {
shadowModJar.archiveFile.get().asFile.inputStream().use { src ->
tasks.jar.get().archiveFile.get().asFile.apply { parentFile.mkdirs() }
.outputStream()
.use { dst -> src.copyTo(dst) }
}
}
}
tasks.assemble.get().dependsOn(copyShadowedJar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment