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