Fix up
This commit is contained in:
parent
fdf165e6e3
commit
88cc5e36e9
|
@ -29,6 +29,7 @@ if (project.hasProperty("libjf_version")) {
|
|||
val devOnlyModules by extra(prop("dev_only_module", "").split(", ", ",").filter { it.isNotBlank() })
|
||||
val nonModSubprojects by extra(prop("non_mod_project", "").split(", ", ",").filter { it.isNotBlank() })
|
||||
val self = project
|
||||
if (hasProperty("maven_group")) group = prop("maven_group")
|
||||
|
||||
allprojects {
|
||||
if (name in nonModSubprojects) return@allprojects
|
||||
|
|
|
@ -4,14 +4,17 @@ import net.fabricmc.loom.task.PrepareJarRemapTask
|
|||
import net.fabricmc.loom.task.RemapJarTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.component.SoftwareComponentFactory
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
import org.gradle.api.tasks.bundling.Jar
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class LomPlugin : Plugin<Project> {
|
||||
class LomPlugin @Inject constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
target.applyLom()
|
||||
}
|
||||
|
@ -33,16 +36,19 @@ class LomPlugin : Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
// Apply necessary plugins
|
||||
apply(plugin = "idea")
|
||||
apply(plugin = "java-library")
|
||||
apply(plugin = "fabric-loom")
|
||||
apply(plugin = "maven-publish")
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
|
||||
// Configure loom for stricter dev env
|
||||
loom {
|
||||
runtimeOnlyLog4j.set(true)
|
||||
splitEnvironmentSourceSets()
|
||||
|
||||
// Class path groups (required to allow ultra early init)
|
||||
mods {
|
||||
register(name) {
|
||||
sourceSet(sourceSets.main)
|
||||
|
@ -54,6 +60,7 @@ class LomPlugin : Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
// Create testmod source set with access to main and client classpaths
|
||||
sourceSets {
|
||||
create("testmod") {
|
||||
compileClasspath += sourceSets.main.compileClasspath
|
||||
|
@ -64,6 +71,7 @@ class LomPlugin : Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
// Common repositories for mods
|
||||
repositories {
|
||||
maven {
|
||||
name = "TerraformersMC"
|
||||
|
@ -89,49 +97,56 @@ class LomPlugin : Plugin<Project> {
|
|||
mavenLocal()
|
||||
}
|
||||
|
||||
// Register dev configuration and add "dev" classifier to unremapped jars
|
||||
configurations.create("dev")
|
||||
tasks.jar.archiveClassifier.set("dev")
|
||||
|
||||
val inputTask: Jar = tasks.findByName("injectCompiledConfig") as Jar? ?: tasks.jar
|
||||
|
||||
tasks.shadow {
|
||||
// configure the shadow task to not shadow by default and output to builds/devlibs
|
||||
tasks.shadowJar {
|
||||
val inputTask: Jar = tasks.findByName("injectCompiledConfig") as Jar? ?: tasks.jar // get injectCompiledConfig task if present (-> LibJF) or use normal jar task
|
||||
dependsOn(inputTask)
|
||||
configurations.clear()
|
||||
from(project.configurations.shadow, tasks.jar.archiveFile.get())
|
||||
from(project.configurations.shadow, inputTask.archiveFile.get())
|
||||
archiveClassifier.set("shadow")
|
||||
destinationDirectory.set(devlibs)
|
||||
}
|
||||
val completeJar = tasks.shadow
|
||||
|
||||
// this is here for some reason
|
||||
// TODO wtf does this do?
|
||||
artifacts.add("dev", tasks.jar.archiveFile.get().asFile) {
|
||||
type = "jar"
|
||||
builtBy(tasks.jar)
|
||||
}
|
||||
|
||||
// generate sources jar to publish for better debugging with dependents
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
// attempt to allow reproducible builds by removing unneeded metadata from jars
|
||||
tasks.withType<AbstractArchiveTask>() {
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = false
|
||||
}
|
||||
|
||||
// generate remapped jar without JiJ'd dependencies for maven publish
|
||||
val remapMavenJar by tasks.registering(RemapJarTask::class) {
|
||||
dependsOn(completeJar)
|
||||
inputFile.set(completeJar.archiveFile.get())
|
||||
dependsOn(tasks.shadowJar.get())
|
||||
inputFile.set(tasks.shadowJar.get().archiveFile.get())
|
||||
archiveFileName.set("${archiveBaseName.get()}-${project.versionS}-maven.jar")
|
||||
addNestedDependencies.set(false)
|
||||
}
|
||||
tasks.assemble.dependsOn(remapMavenJar)
|
||||
|
||||
val testmodJar by tasks.registering(Jar::class) { //TODO include deps
|
||||
// generate jar from testmod source set
|
||||
val testmodJar by tasks.registering(Jar::class) {
|
||||
from(sourceSets.testmod.output)
|
||||
destinationDirectory.set(devlibs)
|
||||
archiveClassifier.set("testmod")
|
||||
}
|
||||
|
||||
val remapTestmodJar by tasks.registering(RemapJarTask::class) {
|
||||
// remap configuration for outputting usable testmod jar
|
||||
val remapTestmodJar by tasks.registering(RemapJarTask::class) { //TODO include deps
|
||||
dependsOn(testmodJar)
|
||||
inputFile.set(testmodJar.archiveFile.get())
|
||||
archiveClassifier.set("testmod")
|
||||
|
@ -139,21 +154,24 @@ class LomPlugin : Plugin<Project> {
|
|||
}
|
||||
tasks.assemble.dependsOn(remapTestmodJar)
|
||||
|
||||
// configure remapJar to use the output of shadow
|
||||
tasks.remapJar {
|
||||
dependsOn(completeJar)
|
||||
inputFile.set(completeJar.archiveFile.get())
|
||||
dependsOn(tasks.shadowJar.get())
|
||||
inputFile.set(tasks.shadowJar.get().archiveFile.get())
|
||||
archiveFileName.set("${archiveBaseName.get()}-${project.versionS}.jar")
|
||||
}
|
||||
|
||||
// fill in mod version
|
||||
tasks.processResources {
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand(mapOf("version" to project.versionS))
|
||||
}
|
||||
}
|
||||
|
||||
// publish sources jar and remapped jar without JiJ'd deps
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
create<MavenPublication>("lom") {
|
||||
from(components["java"])
|
||||
setArtifacts(listOf(remapMavenJar, tasks.sourcesJar))
|
||||
}
|
||||
|
@ -163,10 +181,17 @@ class LomPlugin : Plugin<Project> {
|
|||
tasks.deployDebug.dependsOn(tasks.publish)
|
||||
|
||||
afterEvaluate {
|
||||
// from fabric-example-mod, enforces modern java
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
// otherwise we can't easily overwrite the artifacts to publish while keeping dependency metadata
|
||||
//TODO find a better solution to this (custom component?)
|
||||
tasks.withType<GenerateModuleMetadata> {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
// Fix prepareRemapJar
|
||||
// Finds remapJar tasks and the corresponding prepareRemapJar tasks and ensures the dependencies of remapJar are run before prepareRemapJar
|
||||
|
|
|
@ -8,5 +8,4 @@ import org.gradle.kotlin.dsl.named
|
|||
|
||||
val ConfigurationContainer.shadow: Configuration get() = named("shadow").get()
|
||||
|
||||
val TaskContainer.shadow: ShadowJar get() = named<ShadowJar>("shadowJar").get()
|
||||
fun TaskContainer.shadow(configure: ShadowJar.() -> Unit) = named<ShadowJar>("shadowJar").configure(configure)
|
||||
val TaskContainer.shadowJar get() = named<ShadowJar>("shadowJar")
|
Loading…
Reference in New Issue