mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-15 14:39:40 +00:00
bundle addons in JAR
This commit is contained in:
@@ -2,6 +2,7 @@ package com.dfsek.terra
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
import java.io.File
|
||||
@@ -23,7 +24,7 @@ fun Project.addonDir(dir: File, task: Task) {
|
||||
it.delete()
|
||||
}
|
||||
project(":common:addons").subprojects.forEach { addonProject ->
|
||||
val jar = (addonProject.tasks.named("jar").get() as org.gradle.jvm.tasks.Jar);
|
||||
val jar = (addonProject.tasks.named("jar").get() as Jar)
|
||||
|
||||
val target = File(dir, jar.archiveFileName.get())
|
||||
|
||||
@@ -37,17 +38,7 @@ fun Project.addonDir(dir: File, task: Task) {
|
||||
}
|
||||
|
||||
fun matchingAddons(dir: File, matcher: Predicate<File>): Set<File> {
|
||||
val matching = HashSet<File>();
|
||||
val matching = HashSet<File>()
|
||||
dir.walk().maxDepth(1).asStream().filter(matcher).forEach(matching::add)
|
||||
return matching;
|
||||
return matching
|
||||
}
|
||||
|
||||
fun Project.configureAddons() {
|
||||
tasks.withType<ProcessResources> {
|
||||
project(":common:addons").subprojects.forEach {
|
||||
it.afterEvaluate {
|
||||
dependsOn(it.tasks.getByName("build")) // Depend on addon JARs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,17 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.BasePluginConvention
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.getPlugin
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
fun Project.configureDistribution() {
|
||||
apply(plugin = "java-library")
|
||||
@@ -26,7 +31,43 @@ fun Project.configureDistribution() {
|
||||
downloadPack(netherPackUrl, project)
|
||||
}
|
||||
}
|
||||
|
||||
val installAddons = tasks.create("installAddons") {
|
||||
group = "terra"
|
||||
project(":common:addons").subprojects.forEach {
|
||||
it.afterEvaluate {
|
||||
dependsOn(it.tasks.getByName("build")) // Depend on addon JARs
|
||||
}
|
||||
}
|
||||
|
||||
doFirst {
|
||||
// The addons are copied into a JAR because of a ShadowJar bug
|
||||
// which expands *all* JARs, even resource ones, into the fat JAR.
|
||||
// To get around this, we copy all addon JARs into a *new* JAR,
|
||||
// then, ShadowJar expands the newly created JAR, putting the original
|
||||
// JARs where they should go.
|
||||
//
|
||||
// https://github.com/johnrengelman/shadow/issues/196
|
||||
val dest = File(buildDir, "/resources/main/addons.jar")
|
||||
dest.parentFile.mkdirs()
|
||||
|
||||
val zip = ZipOutputStream(FileOutputStream(dest))
|
||||
|
||||
project(":common:addons").subprojects.forEach { addonProject ->
|
||||
val jar = (addonProject.tasks.named("jar").get() as Jar)
|
||||
println("Packaging addon ${jar.archiveFileName.get()} to ${dest.absolutePath}.")
|
||||
|
||||
val entry = ZipEntry("addons/${jar.archiveFileName.get()}")
|
||||
zip.putNextEntry(entry)
|
||||
FileInputStream(jar.archiveFile.get().asFile).copyTo(zip)
|
||||
zip.closeEntry()
|
||||
}
|
||||
zip.close()
|
||||
}
|
||||
}
|
||||
|
||||
tasks["processResources"].dependsOn(downloadDefaultPacks)
|
||||
tasks["processResources"].dependsOn(installAddons)
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
// Tell shadow to download the packs
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import com.dfsek.terra.configureCompilation
|
||||
import com.dfsek.terra.configureDependencies
|
||||
import com.dfsek.terra.configureAddons
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
@@ -10,7 +9,6 @@ plugins {
|
||||
|
||||
configureCompilation()
|
||||
configureDependencies()
|
||||
configureAddons()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user