mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-12 23:36:09 +01:00
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
This commit is contained in:
parent
3f24efba8a
commit
4c706f23e6
13 changed files with 87 additions and 150 deletions
|
@ -23,18 +23,6 @@ gradlePlugin {
|
||||||
id = "flywheel.platform"
|
id = "flywheel.platform"
|
||||||
implementationClass = "com.jozufozu.gradle.platform.PlatformPlugin"
|
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") {
|
create("subprojectPlugin") {
|
||||||
id = "flywheel.subproject"
|
id = "flywheel.subproject"
|
||||||
implementationClass = "com.jozufozu.gradle.subproject.SubprojectPlugin"
|
implementationClass = "com.jozufozu.gradle.subproject.SubprojectPlugin"
|
||||||
|
|
|
@ -1,16 +1,29 @@
|
||||||
package com.jozufozu.gradle.jarset
|
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.Project
|
||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
import org.gradle.api.tasks.SourceSetContainer
|
import org.gradle.jvm.tasks.Jar
|
||||||
import org.gradle.kotlin.dsl.the
|
import org.gradle.kotlin.dsl.named
|
||||||
|
import org.gradle.kotlin.dsl.provideDelegate
|
||||||
|
|
||||||
open class JarSetExtension(val project: Project) {
|
open class JarSetExtension(private val project: Project) {
|
||||||
fun createJars(name: String): JarTaskSet {
|
fun create(name: String, vararg sourceSetSet: SourceSet): JarTaskSet {
|
||||||
return createJars(name, project.the<SourceSetContainer>().named(name).get())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createJars(name: String, vararg sourceSetSet: SourceSet): JarTaskSet {
|
|
||||||
return JarTaskSet.create(project, name, *sourceSetSet)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.jozufozu.gradle.jarset
|
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
|
||||||
import org.gradle.api.Project
|
|
||||||
|
|
||||||
class JarSetPlugin: Plugin<Project> {
|
|
||||||
override fun apply(target: Project) {
|
|
||||||
target.extensions.create("jarSets", JarSetExtension::class.java, target)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.jozufozu.gradle.jarset
|
package com.jozufozu.gradle.jarset
|
||||||
|
|
||||||
|
import net.fabricmc.loom.task.AbstractRemapJarTask
|
||||||
import net.fabricmc.loom.task.RemapJarTask
|
import net.fabricmc.loom.task.RemapJarTask
|
||||||
import net.fabricmc.loom.task.RemapSourcesJarTask
|
import net.fabricmc.loom.task.RemapSourcesJarTask
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.DuplicatesStrategy
|
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.AbstractCopyTask
|
||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
import org.gradle.api.tasks.SourceTask
|
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.api.tasks.javadoc.Javadoc
|
||||||
import org.gradle.jvm.tasks.Jar
|
import org.gradle.jvm.tasks.Jar
|
||||||
import org.gradle.kotlin.dsl.register
|
import org.gradle.kotlin.dsl.register
|
||||||
|
import org.gradle.kotlin.dsl.the
|
||||||
|
|
||||||
class JarTaskSet(
|
class JarTaskSet(
|
||||||
val project: Project,
|
val project: Project,
|
||||||
|
@ -23,8 +27,30 @@ class JarTaskSet(
|
||||||
val javadocJar: TaskProvider<Jar>
|
val javadocJar: TaskProvider<Jar>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun createOutgoingConfiguration(prefix: String) {
|
fun publishRemap(artifactId: String) {
|
||||||
val config = project.configurations.register("${prefix}${name.capitalize()}") {
|
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
|
isCanBeConsumed = true
|
||||||
isCanBeResolved = false
|
isCanBeResolved = false
|
||||||
}
|
}
|
||||||
|
@ -32,8 +58,10 @@ class JarTaskSet(
|
||||||
project.artifacts.add(config.name, jar)
|
project.artifacts.add(config.name, jar)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun configure(action: Action<JarTaskSet>) {
|
fun assembleRemaps() {
|
||||||
action.execute(this)
|
project.tasks.named("assemble").configure {
|
||||||
|
dependsOn(remapJar, remapSources, javadocJar)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun configureEach(action: Action<Jar>) {
|
fun configureEach(action: Action<Jar>) {
|
||||||
|
@ -45,6 +73,11 @@ class JarTaskSet(
|
||||||
remapSources.configure(action)
|
remapSources.configure(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun configureRemap(action: Action<AbstractRemapJarTask>) {
|
||||||
|
remapJar.configure(action)
|
||||||
|
remapSources.configure(action)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PACKAGE_INFOS_JAVA_PATTERN = "**/package-info.java"
|
private const val PACKAGE_INFOS_JAVA_PATTERN = "**/package-info.java"
|
||||||
private const val BUILD_GROUP: String = "build"
|
private const val BUILD_GROUP: String = "build"
|
||||||
|
@ -127,10 +160,6 @@ class JarTaskSet(
|
||||||
from(javadocTask.map { it.outputs })
|
from(javadocTask.map { it.outputs })
|
||||||
}
|
}
|
||||||
|
|
||||||
project.tasks.named("assemble").configure {
|
|
||||||
dependsOn(remapJarTask, remapSourcesTask, javadocJarTask)
|
|
||||||
}
|
|
||||||
|
|
||||||
return JarTaskSet(project, name, jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask)
|
return JarTaskSet(project, name, jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.jozufozu.gradle.nullability
|
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
|
||||||
import org.gradle.api.Project
|
|
||||||
|
|
||||||
class PackageInfosPlugin: Plugin<Project> {
|
|
||||||
override fun apply(target: Project) {
|
|
||||||
target.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, target)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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 class DependentProject(private val thisProject: Project) : ReadWriteProperty<Any?, Project> {
|
||||||
private var value: Project? = null
|
private var value: Project? = null
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,6 @@ import org.gradle.api.Project
|
||||||
|
|
||||||
class PlatformPlugin: Plugin<Project> {
|
class PlatformPlugin: Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
project.extensions.create("platform", PlatformExtension::class.java)
|
project.extensions.create("platform", PlatformExtension::class.java, project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.jozufozu.gradle.subproject
|
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 net.fabricmc.loom.api.LoomGradleExtensionAPI
|
||||||
import org.gradle.api.JavaVersion
|
import org.gradle.api.JavaVersion
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
|
@ -19,6 +22,10 @@ import org.gradle.language.jvm.tasks.ProcessResources
|
||||||
|
|
||||||
class SubprojectPlugin: Plugin<Project> {
|
class SubprojectPlugin: Plugin<Project> {
|
||||||
override fun apply(project: 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)
|
setBaseProperties(project)
|
||||||
setupJava(project)
|
setupJava(project)
|
||||||
addRepositories(project)
|
addRepositories(project)
|
||||||
|
|
|
@ -13,22 +13,6 @@ open class TransitiveSourceSetsExtension(private val project: Project) {
|
||||||
|
|
||||||
private val transitives = mutableMapOf<SourceSet, TransitiveSourceSetConfigurator>()
|
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) {
|
fun sourceSet(sourceSet: SourceSet) {
|
||||||
registerSourceSet(sourceSet)
|
registerSourceSet(sourceSet)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.jozufozu.gradle.transitive
|
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
|
||||||
import org.gradle.api.Project
|
|
||||||
|
|
||||||
class TransitiveSourceSetsPlugin: Plugin<Project> {
|
|
||||||
override fun apply(target: Project) {
|
|
||||||
target.extensions.create("transitiveSourceSets", TransitiveSourceSetsExtension::class.java, target)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,10 +3,7 @@ plugins {
|
||||||
java
|
java
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("dev.architectury.loom")
|
id("dev.architectury.loom")
|
||||||
id("flywheel.package-infos")
|
|
||||||
id("flywheel.subproject")
|
id("flywheel.subproject")
|
||||||
id("flywheel.jar-sets")
|
|
||||||
id("flywheel.transitive-source-sets")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val api = sourceSets.create("api")
|
val api = sourceSets.create("api")
|
||||||
|
@ -40,16 +37,19 @@ defaultPackageInfos {
|
||||||
sources(api, lib, backend, main)
|
sources(api, lib, backend, main)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For sharing with other subprojects.
|
|
||||||
jarSets {
|
jarSets {
|
||||||
createJars("apiOnly", api).createOutgoingConfiguration("common")
|
// For sharing with other subprojects.
|
||||||
createJars("lib").createOutgoingConfiguration("common")
|
outgoing("commonApiOnly", api)
|
||||||
createJars("backend").createOutgoingConfiguration("common")
|
outgoing("commonLib", lib)
|
||||||
createJars("impl", main).createOutgoingConfiguration("common")
|
outgoing("commonBackend", backend)
|
||||||
}
|
outgoing("commonImpl", main)
|
||||||
|
|
||||||
// For publishing
|
// For publishing.
|
||||||
val apiLibJar = jarSets.createJars("api", api, lib)
|
create("api", api, lib).apply {
|
||||||
|
publish("flywheel-common-mojmap-api-${property("artifact_minecraft_version")}")
|
||||||
|
publishRemap("flywheel-common-intermediary-api-${property("artifact_minecraft_version")}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")
|
modCompileOnly("net.fabricmc:fabric-loader:${property("fabric_loader_version")}")
|
||||||
|
@ -60,20 +60,3 @@ dependencies {
|
||||||
tasks.test {
|
tasks.test {
|
||||||
useJUnitPlatform()
|
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")}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,11 +3,8 @@ plugins {
|
||||||
java
|
java
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("dev.architectury.loom")
|
id("dev.architectury.loom")
|
||||||
id("flywheel.package-infos")
|
|
||||||
id("flywheel.subproject")
|
id("flywheel.subproject")
|
||||||
id("flywheel.platform")
|
id("flywheel.platform")
|
||||||
id("flywheel.jar-sets")
|
|
||||||
id("flywheel.transitive-source-sets")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val api = sourceSets.create("api")
|
val api = sourceSets.create("api")
|
||||||
|
@ -43,8 +40,11 @@ platform {
|
||||||
setupLoomMod()
|
setupLoomMod()
|
||||||
setupLoomRuns()
|
setupLoomRuns()
|
||||||
setupFatJar()
|
setupFatJar()
|
||||||
publishMod()
|
}
|
||||||
publishRemap(apiArtifactId, jarSets.createJars("api", api, lib))
|
|
||||||
|
jarSets {
|
||||||
|
mainSet.publishRemap(platform.modArtifactId)
|
||||||
|
create("api", api, lib).publishRemap(platform.apiArtifactId)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultPackageInfos {
|
defaultPackageInfos {
|
||||||
|
|
|
@ -3,11 +3,8 @@ plugins {
|
||||||
java
|
java
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("dev.architectury.loom")
|
id("dev.architectury.loom")
|
||||||
id("flywheel.package-infos")
|
|
||||||
id("flywheel.subproject")
|
id("flywheel.subproject")
|
||||||
id("flywheel.platform")
|
id("flywheel.platform")
|
||||||
id("flywheel.jar-sets")
|
|
||||||
id("flywheel.transitive-source-sets")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val api = sourceSets.create("api")
|
val api = sourceSets.create("api")
|
||||||
|
@ -43,8 +40,11 @@ platform {
|
||||||
setupLoomMod()
|
setupLoomMod()
|
||||||
setupLoomRuns()
|
setupLoomRuns()
|
||||||
setupFatJar()
|
setupFatJar()
|
||||||
publishMod()
|
}
|
||||||
publishRemap(apiArtifactId, jarSets.createJars("api", api, lib))
|
|
||||||
|
jarSets {
|
||||||
|
mainSet.publishRemap(platform.modArtifactId)
|
||||||
|
create("api", api, lib).publishRemap(platform.apiArtifactId)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultPackageInfos {
|
defaultPackageInfos {
|
||||||
|
|
Loading…
Reference in a new issue