From bba587fa198335467285128e757e6e668a896704 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 4 May 2024 15:45:58 -0700 Subject: [PATCH] Less is more - Merge package-infos, jar-sets, and transitive-source-sets plugins - Move publishing logic into JarTaskSet - Do not eagerly add all jarsets to assemble - Significantly reduces build times - Add separate helper method for creating outgoing jarsets --- buildSrc/build.gradle.kts | 12 ----- .../jozufozu/gradle/jarset/JarSetExtension.kt | 27 ++++++++--- .../jozufozu/gradle/jarset/JarSetPlugin.kt | 10 ----- .../com/jozufozu/gradle/jarset/JarTaskSet.kt | 45 +++++++++++++++---- .../gradle/nullability/PackageInfosPlugin.kt | 10 ----- .../gradle/platform/PlatformExtension.kt | 37 --------------- .../gradle/platform/PlatformPlugin.kt | 2 +- .../gradle/subproject/SubprojectPlugin.kt | 7 +++ .../TransitiveSourceSetsExtension.kt | 16 ------- .../transitive/TransitiveSourceSetsPlugin.kt | 10 ----- common/build.gradle.kts | 39 +++++----------- fabric/build.gradle.kts | 10 ++--- forge/build.gradle.kts | 10 ++--- 13 files changed, 86 insertions(+), 149 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetPlugin.kt delete mode 100644 buildSrc/src/main/kotlin/com/jozufozu/gradle/nullability/PackageInfosPlugin.kt delete mode 100644 buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsPlugin.kt diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 885339096..312a2b4a3 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -23,18 +23,6 @@ gradlePlugin { id = "flywheel.platform" implementationClass = "com.jozufozu.gradle.platform.PlatformPlugin" } - create("jarSetPlugin") { - id = "flywheel.jar-sets" - implementationClass = "com.jozufozu.gradle.jarset.JarSetPlugin" - } - create("packageInfosPlugin") { - id = "flywheel.package-infos" - implementationClass = "com.jozufozu.gradle.nullability.PackageInfosPlugin" - } - create("transitiveSourceSetsPlugin") { - id = "flywheel.transitive-source-sets" - implementationClass = "com.jozufozu.gradle.transitive.TransitiveSourceSetsPlugin" - } create("subprojectPlugin") { id = "flywheel.subproject" implementationClass = "com.jozufozu.gradle.subproject.SubprojectPlugin" diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt index f20fcd881..fea600095 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt @@ -1,16 +1,29 @@ package com.jozufozu.gradle.jarset +import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.task.RemapSourcesJarTask import org.gradle.api.Project import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceSetContainer -import org.gradle.kotlin.dsl.the +import org.gradle.jvm.tasks.Jar +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.provideDelegate -open class JarSetExtension(val project: Project) { - fun createJars(name: String): JarTaskSet { - return createJars(name, project.the().named(name).get()) +open class JarSetExtension(private val project: Project) { + fun create(name: String, vararg sourceSetSet: SourceSet): JarTaskSet { + return JarTaskSet.create(project, name, *sourceSetSet) } - fun createJars(name: String, vararg sourceSetSet: SourceSet): JarTaskSet { - return JarTaskSet.create(project, name, *sourceSetSet) + fun outgoing(name: String, vararg sourceSetSet: SourceSet): JarTaskSet { + return JarTaskSet.create(project, name, *sourceSetSet).also { it.createOutgoingConfiguration() } + } + + val mainSet: JarTaskSet by lazy { + val jarTask = project.tasks.named("jar") + val remapJarTask = project.tasks.named("remapJar") + val sourcesJarTask = project.tasks.named("sourcesJar") + val remapSourcesJarTask = project.tasks.named("remapSourcesJar") + val javadocJarTask = project.tasks.named("javadocJar") + + JarTaskSet(project, "main", jarTask, remapJarTask, sourcesJarTask, remapSourcesJarTask, javadocJarTask) } } diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetPlugin.kt deleted file mode 100644 index a1895b440..000000000 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetPlugin.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.jozufozu.gradle.jarset - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class JarSetPlugin: Plugin { - override fun apply(target: Project) { - target.extensions.create("jarSets", JarSetExtension::class.java, target) - } -} diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt index 194dd63ed..3e925626c 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt @@ -1,10 +1,13 @@ package com.jozufozu.gradle.jarset +import net.fabricmc.loom.task.AbstractRemapJarTask import net.fabricmc.loom.task.RemapJarTask import net.fabricmc.loom.task.RemapSourcesJarTask import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.AbstractCopyTask import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceTask @@ -12,6 +15,7 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.the class JarTaskSet( val project: Project, @@ -23,8 +27,30 @@ class JarTaskSet( val javadocJar: TaskProvider ) { - fun createOutgoingConfiguration(prefix: String) { - val config = project.configurations.register("${prefix}${name.capitalize()}") { + fun publishRemap(artifactId: String) { + project.the().publications { + register("${name}RemapMaven") { + artifact(remapJar) + artifact(remapSources) + artifact(javadocJar) + this.artifactId = artifactId + } + } + } + + fun publish(artifactId: String) { + project.the().publications { + register("${name}Maven") { + artifact(jar) + artifact(sources) + artifact(javadocJar) + this.artifactId = artifactId + } + } + } + + fun createOutgoingConfiguration() { + val config = project.configurations.register(name) { isCanBeConsumed = true isCanBeResolved = false } @@ -32,8 +58,10 @@ class JarTaskSet( project.artifacts.add(config.name, jar) } - fun configure(action: Action) { - action.execute(this) + fun assembleRemaps() { + project.tasks.named("assemble").configure { + dependsOn(remapJar, remapSources, javadocJar) + } } fun configureEach(action: Action) { @@ -45,6 +73,11 @@ class JarTaskSet( remapSources.configure(action) } + fun configureRemap(action: Action) { + remapJar.configure(action) + remapSources.configure(action) + } + companion object { private const val PACKAGE_INFOS_JAVA_PATTERN = "**/package-info.java" private const val BUILD_GROUP: String = "build" @@ -127,10 +160,6 @@ class JarTaskSet( from(javadocTask.map { it.outputs }) } - project.tasks.named("assemble").configure { - dependsOn(remapJarTask, remapSourcesTask, javadocJarTask) - } - return JarTaskSet(project, name, jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask) } } diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/nullability/PackageInfosPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/nullability/PackageInfosPlugin.kt deleted file mode 100644 index 8c50240f0..000000000 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/nullability/PackageInfosPlugin.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.jozufozu.gradle.nullability - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class PackageInfosPlugin: Plugin { - override fun apply(target: Project) { - target.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, target) - } -} diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt index 46ae6d542..2b5268a18 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformExtension.kt @@ -108,43 +108,6 @@ open class PlatformExtension(val project: Project) { } } - fun publishMod() { - val remapJar = project.tasks.named("remapJar") - val remapSourcesJar = project.tasks.named("remapSourcesJar") - val javadocJar = project.tasks.named("javadocJar") - - project.the().publications { - register("modMaven") { - artifact(remapJar) - artifact(remapSourcesJar) - artifact(javadocJar) - artifactId = modArtifactId - } - } - } - - fun publishRemap(artifactId: String, jarSet: JarTaskSet) { - project.the().publications { - register("${jarSet.name}RemapMaven") { - artifact(jarSet.remapJar) - artifact(jarSet.remapSources) - artifact(jarSet.javadocJar) - this.artifactId = artifactId - } - } - } - - fun publish(artifactId: String, jarSet: JarTaskSet) { - project.the().publications { - register("${jarSet.name}Maven") { - artifact(jarSet.jar) - artifact(jarSet.sources) - artifact(jarSet.javadocJar) - this.artifactId = artifactId - } - } - } - private class DependentProject(private val thisProject: Project) : ReadWriteProperty { private var value: Project? = null diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformPlugin.kt index e3284c103..652a51121 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformPlugin.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/platform/PlatformPlugin.kt @@ -5,6 +5,6 @@ import org.gradle.api.Project class PlatformPlugin: Plugin { override fun apply(project: Project) { - project.extensions.create("platform", PlatformExtension::class.java) + project.extensions.create("platform", PlatformExtension::class.java, project) } } diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt index 6c36a48b0..b448b7e0d 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/subproject/SubprojectPlugin.kt @@ -1,5 +1,8 @@ package com.jozufozu.gradle.subproject +import com.jozufozu.gradle.jarset.JarSetExtension +import com.jozufozu.gradle.nullability.PackageInfosExtension +import com.jozufozu.gradle.transitive.TransitiveSourceSetsExtension import net.fabricmc.loom.api.LoomGradleExtensionAPI import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -19,6 +22,10 @@ import org.gradle.language.jvm.tasks.ProcessResources class SubprojectPlugin: Plugin { override fun apply(project: Project) { + project.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, project) + project.extensions.create("transitiveSourceSets", TransitiveSourceSetsExtension::class.java, project) + project.extensions.create("jarSets", JarSetExtension::class.java, project) + setBaseProperties(project) setupJava(project) addRepositories(project) diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt index 020234cc5..e549cc158 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsExtension.kt @@ -13,22 +13,6 @@ open class TransitiveSourceSetsExtension(private val project: Project) { private val transitives = mutableMapOf() - fun create(name: String) { - sourceSet(project.the().maybeCreate(name)) - } - - fun create(name: String, action: Action) { - sourceSet(project.the().maybeCreate(name), action) - } - - fun sourceSet(name: String) { - sourceSet(project.the().getByName(name)) - } - - fun sourceSet(name: String, action: Action) { - sourceSet(project.the().getByName(name), action) - } - fun sourceSet(sourceSet: SourceSet) { registerSourceSet(sourceSet) } diff --git a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsPlugin.kt b/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsPlugin.kt deleted file mode 100644 index 8eb33eec6..000000000 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/transitive/TransitiveSourceSetsPlugin.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.jozufozu.gradle.transitive - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class TransitiveSourceSetsPlugin: Plugin { - override fun apply(target: Project) { - target.extensions.create("transitiveSourceSets", TransitiveSourceSetsExtension::class.java, target) - } -} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 5b3dc91ed..cd4b81ca1 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -3,10 +3,7 @@ plugins { java `maven-publish` id("dev.architectury.loom") - id("flywheel.package-infos") id("flywheel.subproject") - id("flywheel.jar-sets") - id("flywheel.transitive-source-sets") } val api = sourceSets.create("api") @@ -40,17 +37,20 @@ defaultPackageInfos { sources(api, lib, backend, main) } -// For sharing with other subprojects. jarSets { - createJars("apiOnly", api).createOutgoingConfiguration("common") - createJars("lib").createOutgoingConfiguration("common") - createJars("backend").createOutgoingConfiguration("common") - createJars("impl", main).createOutgoingConfiguration("common") + // For sharing with other subprojects. + outgoing("commonApiOnly", api) + outgoing("commonLib", lib) + outgoing("commonBackend", backend) + outgoing("commonImpl", main) + + // For publishing. + create("api", api, lib).apply { + publish("flywheel-common-mojmap-api-${property("artifact_minecraft_version")}") + publishRemap("flywheel-common-intermediary-api-${property("artifact_minecraft_version")}") + } } -// For publishing -val apiLibJar = jarSets.createJars("api", api, lib) - dependencies { modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}") @@ -60,20 +60,3 @@ dependencies { tasks.test { useJUnitPlatform() } - -publishing { - publications { - register("mavenIntermediary") { - artifact(apiLibJar.remapJar) - artifact(apiLibJar.remapSources) - artifact(apiLibJar.javadocJar) - artifactId = "flywheel-common-intermediary-api-${property("artifact_minecraft_version")}" - } - register("mavenMojmap") { - artifact(apiLibJar.jar) - artifact(apiLibJar.sources) - artifact(apiLibJar.javadocJar) - artifactId = "flywheel-common-mojmap-api-${property("artifact_minecraft_version")}" - } - } -} diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index ba208fd19..131955622 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -3,11 +3,8 @@ plugins { java `maven-publish` id("dev.architectury.loom") - id("flywheel.package-infos") id("flywheel.subproject") id("flywheel.platform") - id("flywheel.jar-sets") - id("flywheel.transitive-source-sets") } val api = sourceSets.create("api") @@ -43,8 +40,11 @@ platform { setupLoomMod() setupLoomRuns() setupFatJar() - publishMod() - publishRemap(apiArtifactId, jarSets.createJars("api", api, lib)) +} + +jarSets { + mainSet.publishRemap(platform.modArtifactId) + create("api", api, lib).publishRemap(platform.apiArtifactId) } defaultPackageInfos { diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 158c307f5..8393ade99 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -3,11 +3,8 @@ plugins { java `maven-publish` id("dev.architectury.loom") - id("flywheel.package-infos") id("flywheel.subproject") id("flywheel.platform") - id("flywheel.jar-sets") - id("flywheel.transitive-source-sets") } val api = sourceSets.create("api") @@ -43,8 +40,11 @@ platform { setupLoomMod() setupLoomRuns() setupFatJar() - publishMod() - publishRemap(apiArtifactId, jarSets.createJars("api", api, lib)) +} + +jarSets { + mainSet.publishRemap(platform.modArtifactId) + create("api", api, lib).publishRemap(platform.apiArtifactId) } defaultPackageInfos {