Skip to content

Commit

Permalink
Less is more
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Jozufozu committed May 4, 2024
1 parent e07d658 commit bba587f
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 149 deletions.
12 changes: 0 additions & 12 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SourceSetContainer>().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>("jar")
val remapJarTask = project.tasks.named<RemapJarTask>("remapJar")
val sourcesJarTask = project.tasks.named<Jar>("sourcesJar")
val remapSourcesJarTask = project.tasks.named<RemapSourcesJarTask>("remapSourcesJar")
val javadocJarTask = project.tasks.named<Jar>("javadocJar")

JarTaskSet(project, "main", jarTask, remapJarTask, sourcesJarTask, remapSourcesJarTask, javadocJarTask)
}
}

This file was deleted.

45 changes: 37 additions & 8 deletions buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
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
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,
Expand All @@ -23,17 +27,41 @@ class JarTaskSet(
val javadocJar: TaskProvider<Jar>
) {

fun createOutgoingConfiguration(prefix: String) {
val config = project.configurations.register("${prefix}${name.capitalize()}") {
fun publishRemap(artifactId: String) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${name}RemapMaven") {
artifact(remapJar)
artifact(remapSources)
artifact(javadocJar)
this.artifactId = artifactId
}
}
}

fun publish(artifactId: String) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${name}Maven") {
artifact(jar)
artifact(sources)
artifact(javadocJar)
this.artifactId = artifactId
}
}
}

fun createOutgoingConfiguration() {
val config = project.configurations.register(name) {
isCanBeConsumed = true
isCanBeResolved = false
}

project.artifacts.add(config.name, jar)
}

fun configure(action: Action<JarTaskSet>) {
action.execute(this)
fun assembleRemaps() {
project.tasks.named("assemble").configure {
dependsOn(remapJar, remapSources, javadocJar)
}
}

fun configureEach(action: Action<Jar>) {
Expand All @@ -45,6 +73,11 @@ class JarTaskSet(
remapSources.configure(action)
}

fun configureRemap(action: Action<AbstractRemapJarTask>) {
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"
Expand Down Expand Up @@ -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)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,6 @@ open class PlatformExtension(val project: Project) {
}
}

fun publishMod() {
val remapJar = project.tasks.named<RemapJarTask>("remapJar")
val remapSourcesJar = project.tasks.named<RemapSourcesJarTask>("remapSourcesJar")
val javadocJar = project.tasks.named<Jar>("javadocJar")

project.the<PublishingExtension>().publications {
register<MavenPublication>("modMaven") {
artifact(remapJar)
artifact(remapSourcesJar)
artifact(javadocJar)
artifactId = modArtifactId
}
}
}

fun publishRemap(artifactId: String, jarSet: JarTaskSet) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${jarSet.name}RemapMaven") {
artifact(jarSet.remapJar)
artifact(jarSet.remapSources)
artifact(jarSet.javadocJar)
this.artifactId = artifactId
}
}
}

fun publish(artifactId: String, jarSet: JarTaskSet) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${jarSet.name}Maven") {
artifact(jarSet.jar)
artifact(jarSet.sources)
artifact(jarSet.javadocJar)
this.artifactId = artifactId
}
}
}

private class DependentProject(private val thisProject: Project) : ReadWriteProperty<Any?, Project> {
private var value: Project? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import org.gradle.api.Project

class PlatformPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.extensions.create("platform", PlatformExtension::class.java)
project.extensions.create("platform", PlatformExtension::class.java, project)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +22,10 @@ import org.gradle.language.jvm.tasks.ProcessResources

class SubprojectPlugin: Plugin<Project> {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ open class TransitiveSourceSetsExtension(private val project: Project) {

private val transitives = mutableMapOf<SourceSet, TransitiveSourceSetConfigurator>()

fun create(name: String) {
sourceSet(project.the<SourceSetContainer>().maybeCreate(name))
}

fun create(name: String, action: Action<TransitiveSourceSetConfigurator>) {
sourceSet(project.the<SourceSetContainer>().maybeCreate(name), action)
}

fun sourceSet(name: String) {
sourceSet(project.the<SourceSetContainer>().getByName(name))
}

fun sourceSet(name: String, action: Action<TransitiveSourceSetConfigurator>) {
sourceSet(project.the<SourceSetContainer>().getByName(name), action)
}

fun sourceSet(sourceSet: SourceSet) {
registerSourceSet(sourceSet)
}
Expand Down

This file was deleted.

39 changes: 11 additions & 28 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")}")

Expand All @@ -60,20 +60,3 @@ dependencies {
tasks.test {
useJUnitPlatform()
}

publishing {
publications {
register<MavenPublication>("mavenIntermediary") {
artifact(apiLibJar.remapJar)
artifact(apiLibJar.remapSources)
artifact(apiLibJar.javadocJar)
artifactId = "flywheel-common-intermediary-api-${property("artifact_minecraft_version")}"
}
register<MavenPublication>("mavenMojmap") {
artifact(apiLibJar.jar)
artifact(apiLibJar.sources)
artifact(apiLibJar.javadocJar)
artifactId = "flywheel-common-mojmap-api-${property("artifact_minecraft_version")}"
}
}
}
10 changes: 5 additions & 5 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bba587f

Please sign in to comment.