From 1406d21d83e0b321c90da60bb1aeb7ec81ca5d8c Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 27 Apr 2024 19:25:02 -0700 Subject: [PATCH] Publicity stunt - Only publish api/lib and full jars for platforms - Do not eagerly create outgoing configurations for JarTaskSet - Add method to create outgoing configuration - Clean up JarTaskSet creation and move some string constants to statics - Set @CompileStatic - Remove ${name} classifier prefix from JarTaskSet jars - Put JarTaskSet jars into subdirectories in the output folders - Add configure and configureEach methods to JarTaskSet - Rename OutgoingConfigurationPlugin -> JarSetPlugin and move extension to root module so idea offers completions in gradle files - Standardize artifact naming flywheel-$platform(-api)?-$mcversion --- buildSrc/build.gradle | 12 +- .../com/jozufozu/gradle/JarSetPlugin.groovy | 33 ++++++ .../com/jozufozu/gradle/JarTaskSet.groovy | 106 +++++++++++++++++- .../com/jozufozu/gradle/JarTaskUtils.groovy | 75 ++----------- .../gradle/OutgoingConfigurationPlugin.groovy | 30 ----- .../com/jozufozu/gradle/PlatformPlugin.groovy | 46 ++++---- common/build.gradle | 60 ++++------ 7 files changed, 197 insertions(+), 165 deletions(-) create mode 100644 buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy delete mode 100644 buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index c3c11c5ef..b80ca0bb3 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -19,13 +19,13 @@ repositories { gradlePlugin { plugins { - platformPlugin { - id = 'flywheel.platform' - implementationClass = 'com.jozufozu.gradle.PlatformPlugin' + platformPlugin { PluginDeclaration plugin -> + plugin.id = 'flywheel.platform' + plugin.implementationClass = 'com.jozufozu.gradle.PlatformPlugin' } - outgoingConfigurationPlugin { - id = 'flywheel.outgoing-configuration' - implementationClass = 'com.jozufozu.gradle.OutgoingConfigurationPlugin' + jarSetPlugin { PluginDeclaration plugin -> + plugin.id = 'flywheel.jar-sets' + plugin.implementationClass = 'com.jozufozu.gradle.JarSetPlugin' } } } diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy new file mode 100644 index 000000000..4fc44a19a --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarSetPlugin.groovy @@ -0,0 +1,33 @@ +package com.jozufozu.gradle + + +import groovy.transform.CompileStatic +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer + +@CompileStatic +class JarSetPlugin implements Plugin { + @Override + void apply(Project project) { + project.extensions.create("jarSets", JarSetExtension, project) + } +} + +@CompileStatic +class JarSetExtension { + private final Project project + + JarSetExtension(Project project) { + this.project = project + } + + JarTaskSet createJars(String name) { + return createJars(name, project.getExtensions().getByType(SourceSetContainer).named(name).get()) + } + + JarTaskSet createJars(String name, SourceSet... sourceSetSet) { + return JarTaskSet.create(project, name, sourceSetSet) + } +} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy index d14ed925c..f75c93b0b 100644 --- a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy @@ -1,22 +1,126 @@ package com.jozufozu.gradle +import groovy.transform.CompileStatic 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.tasks.SourceSet import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.Jar +import org.gradle.api.tasks.javadoc.Javadoc +@CompileStatic class JarTaskSet { + public static final String BUILD_GROUP = 'build' + public static final String LOOM_GROUP = 'loom' + public static final String JAVADOC_CLASSIFIER = "javadoc" + public static final String SOURCES_CLASSIFIER = "sources" + + Project project + String name TaskProvider jar TaskProvider remapJar TaskProvider sources TaskProvider remapSources TaskProvider javadocJar - JarTaskSet(TaskProvider jar, TaskProvider remapJar, TaskProvider sources, TaskProvider remapSources, TaskProvider javadocJar) { + JarTaskSet(Project project, String name, TaskProvider jar, TaskProvider remapJar, TaskProvider sources, TaskProvider remapSources, TaskProvider javadocJar) { + this.project = project + this.name = name this.jar = jar this.remapJar = remapJar this.sources = sources this.remapSources = remapSources this.javadocJar = javadocJar } + + void createOutgoingConfiguration(String prefix) { + def config = project.configurations.register("${prefix}${name.capitalize()}") { + it.canBeConsumed = true + it.canBeResolved = false + } + + project.artifacts.add(config.name, jar) + } + + void configure(Action action) { + action.execute(this) + } + + void configureEach(Action action) { + jar.configure(action) + sources.configure(action) + javadocJar.configure(action) + + remapJar.configure(action as Action) + remapSources.configure(action as Action) + } + + static JarTaskSet create(Project project, String name, SourceSet... sourceSetSet) { + def buildDirectory = project.layout.buildDirectory + def devlibs = buildDirectory.dir("devlibs/${name}") + def libs = buildDirectory.dir("libs/${name}") + + def jarTask = project.tasks.register("${name}Jar", Jar) { + it.group = BUILD_GROUP + it.destinationDirectory.set(devlibs) + + for (SourceSet set in sourceSetSet) { + it.from set.output + } + JarTaskUtils.excludeDuplicatePackageInfos(it) + } + def remapJarTask = project.tasks.register("${name}RemapJar", RemapJarTask) { + it.dependsOn(jarTask) + it.group = LOOM_GROUP + it.destinationDirectory.set(libs) + + it.inputFile.set(jarTask.flatMap { it.archiveFile }) + } + def sourcesTask = project.tasks.register("${name}SourcesJar", Jar) { + it.group = BUILD_GROUP + it.destinationDirectory.set(devlibs) + it.archiveClassifier.set(SOURCES_CLASSIFIER) + + for (SourceSet set in sourceSetSet) { + it.from set.allSource + } + JarTaskUtils.excludeDuplicatePackageInfos(it) + } + def remapSourcesTask = project.tasks.register("${name}RemapSourcesJar", RemapSourcesJarTask) { + it.dependsOn(sourcesTask) + it.group = LOOM_GROUP + it.destinationDirectory.set(libs) + it.archiveClassifier.set(SOURCES_CLASSIFIER) + + it.inputFile.set(sourcesTask.flatMap { it.archiveFile }) + } + def javadocTask = project.tasks.register("${name}Javadoc", Javadoc) { + it.group = BUILD_GROUP + it.destinationDir = buildDirectory.dir("docs/${name}-javadoc").get().asFile + it.options.encoding = 'UTF-8' + it.options.optionFiles(project.rootProject.file('javadoc-options.txt')) + + for (SourceSet set in sourceSetSet) { + it.source set.allJava + it.classpath += set.compileClasspath + } + JarTaskUtils.excludeDuplicatePackageInfos(it) + } + def javadocJarTask = project.tasks.register("${name}JavadocJar", Jar) { + it.dependsOn(javadocTask) + it.group = BUILD_GROUP + it.destinationDirectory.set(libs) + it.archiveClassifier.set(JAVADOC_CLASSIFIER) + + it.from(javadocTask.map { it.outputs }) + } + + project.tasks.named('assemble').configure { + it.dependsOn(remapJarTask, remapSourcesTask, javadocJarTask) + } + + return new JarTaskSet(project, name, jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask) + } } diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskUtils.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskUtils.groovy index 9535497c5..c178124fe 100644 --- a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskUtils.groovy +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskUtils.groovy @@ -1,8 +1,10 @@ package com.jozufozu.gradle +import groovy.transform.CompileStatic import net.fabricmc.loom.task.RemapJarTask import net.fabricmc.loom.task.RemapSourcesJarTask import org.gradle.api.Project +import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.FileCopyDetails import org.gradle.api.tasks.AbstractCopyTask @@ -11,80 +13,23 @@ import org.gradle.api.tasks.SourceTask import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.javadoc.Javadoc +@CompileStatic class JarTaskUtils { - // We have duplicate packages between the common and platform dependent subprojects. - // In theory the package-info.java files should be identical, so just take the first one we find. + /** + * We have duplicate packages between the common and platform dependent subprojects. + * In theory the package-info.java files should be identical, so just take the first one we find. + */ static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) { copyTask.filesMatching('**/package-info.java') { FileCopyDetails details -> details.duplicatesStrategy = DuplicatesStrategy.EXCLUDE } } - // The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling. + /** + * The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling. + */ static void excludeDuplicatePackageInfos(SourceTask sourceTask) { sourceTask.exclude('**/package-info.java') } - static JarTaskSet createJarAndOutgoingConfiguration(Project project, String name, SourceSet... sourceSetSet) { - def config = project.configurations.register("common${name.capitalize()}") { - canBeConsumed = true - canBeResolved = false - } - def jarTask = project.tasks.register("${name}Jar", Jar) { - group = 'Build' - archiveClassifier.set(name) - destinationDirectory.set(project.layout.buildDirectory.dir('devlibs')) - for (SourceSet set in sourceSetSet) { - from set.output - } - excludeDuplicatePackageInfos(it) - } - def remapJarTask = project.tasks.register("${name}RemapJar", RemapJarTask) { - group = 'Loom' - dependsOn(jarTask) - archiveClassifier.set(name) - inputFile.set(jarTask.flatMap { it.archiveFile }) - } - def sourcesTask = project.tasks.register("${name}SourcesJar", Jar) { - group = 'Build' - archiveClassifier.set("${name}-sources") - destinationDirectory.set(project.layout.buildDirectory.dir('devlibs')) - for (SourceSet set in sourceSetSet) { - from set.allSource - } - excludeDuplicatePackageInfos(it) - } - def remapSourcesTask = project.tasks.register("${name}RemapSourcesJar", RemapSourcesJarTask) { - group = 'Loom' - dependsOn(sourcesTask) - archiveClassifier.set("${name}-sources") - inputFile.set(sourcesTask.flatMap { it.archiveFile }) - } - def javadocTask = project.tasks.register("${name}Javadoc", Javadoc) { - group = 'Build' - destinationDir = project.layout.buildDirectory.dir("docs/${name}-javadoc").get().asFile - options.encoding = 'UTF-8' - options.optionFiles(project.rootProject.file('javadoc-options.txt')) - for (SourceSet set in sourceSetSet) { - source set.allJava - classpath += set.compileClasspath - } - excludeDuplicatePackageInfos(it) - } - def javadocJarTask = project.tasks.register("${name}JavadocJar", Jar) { - group = 'Build' - dependsOn(javadocTask) - archiveClassifier.set("${name}-javadoc") - destinationDirectory.set(project.layout.buildDirectory.dir('libs')) - from(javadocTask.map { it.outputs }) - } - - project.artifacts.add(config.name, jarTask) - - project.tasks.named('assemble').configure { - dependsOn(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocTask, javadocJarTask) - } - - return new JarTaskSet(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask) - } } diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy deleted file mode 100644 index 468b59f97..000000000 --- a/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy +++ /dev/null @@ -1,30 +0,0 @@ -package com.jozufozu.gradle - - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceSetContainer - -class OutgoingConfigurationPlugin implements Plugin { - @Override - void apply(Project project) { - project.extensions.create("outgoing", Extension, project) - } - - static class Extension { - private final Project project - - Extension(Project project) { - this.project = project - } - - JarTaskSet createJarAndOutgoingConfiguration(String name) { - return createJarAndOutgoingConfiguration(name, project.getExtensions().getByType(SourceSetContainer).named(name).get()) - } - - JarTaskSet createJarAndOutgoingConfiguration(String name, SourceSet... sourceSetSet) { - return JarTaskUtils.createJarAndOutgoingConfiguration(project, name, sourceSetSet) - } - } -} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/PlatformPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/PlatformPlugin.groovy index 476ded6f8..055b2ba4b 100644 --- a/buildSrc/src/main/groovy/com/jozufozu/gradle/PlatformPlugin.groovy +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/PlatformPlugin.groovy @@ -2,6 +2,9 @@ package com.jozufozu.gradle import groovy.transform.CompileStatic import net.fabricmc.loom.api.LoomGradleExtensionAPI +import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.task.RemapSourcesJarTask +import org.gradle.api.NamedDomainObjectProvider import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration @@ -56,10 +59,10 @@ class PlatformPlugin implements Plugin { mainMod.sourceSet(platformBackend) mainMod.sourceSet(platformImpl) - def forApi = newConfiguration(project, 'forApi') - def forLib = newConfiguration(project, 'forLib') - def forBackend = newConfiguration(project, 'forBackend') - def forImpl = newConfiguration(project, 'forImpl') + def forApi = newConfiguration(project, 'forApi').get() + def forLib = newConfiguration(project, 'forLib').get() + def forBackend = newConfiguration(project, 'forBackend').get() + def forImpl = newConfiguration(project, 'forImpl').get() extendsFrom(project, platformApi.compileOnlyConfigurationName, forApi) extendsFrom(project, platformLib.compileOnlyConfigurationName, forApi, forLib) @@ -86,7 +89,6 @@ class PlatformPlugin implements Plugin { } tasks.named('jar', Jar).configure { Jar jar -> - jar.archiveClassifier.set('dev') jar.from platformApi.output, platformLib.output, platformBackend.output JarTaskUtils.excludeDuplicatePackageInfos(jar) @@ -108,34 +110,34 @@ class PlatformPlugin implements Plugin { JarTaskUtils.excludeDuplicatePackageInfos(jar) } - // for if we decide to have Vanillin be another subproject, we can just use the exported configurations - JarTaskUtils.createJarAndOutgoingConfiguration(project, 'apiOnly', platformApi) - JarTaskUtils.createJarAndOutgoingConfiguration(project, 'lib', platformLib) + def remapJar = tasks.named('remapJar', RemapJarTask) + def remapSourcesJar = tasks.named('remapSourcesJar', RemapSourcesJarTask) + def javadocJar = tasks.named('javadocJar', Jar) - JarTaskSet apiSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'api', platformApi, platformLib) - JarTaskSet backendSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'backend', platformBackend) - JarTaskSet implSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'impl', platformImpl) + JarTaskSet apiSet = JarTaskSet.create(project, 'api', platformApi, platformLib) + + def mcVersion = project.property('artifact_minecraft_version') publishing.publications { // we should be using remapped on both Fabric and Forge because Forge needs to put things in srg - it.register('mavenIntermediary', MavenPublication) { MavenPublication pub -> - pub.from(project.components.named('java').get()) + it.register('mavenApi', MavenPublication) { MavenPublication pub -> pub.artifact(apiSet.remapJar) pub.artifact(apiSet.remapSources) pub.artifact(apiSet.javadocJar) - pub.artifact(backendSet.remapJar) - pub.artifact(backendSet.remapSources) - pub.artifact(backendSet.javadocJar) - pub.artifact(implSet.remapJar) - pub.artifact(implSet.remapSources) - pub.artifact(implSet.javadocJar) - pub.artifactId = "flywheel-${project.name}-${project.property('artifact_minecraft_version')}" + + pub.artifactId = "flywheel-${project.name}-api-${mcVersion}" + } + it.register('mavenImpl', MavenPublication) { MavenPublication pub -> + pub.artifact(remapJar) + pub.artifact(remapSourcesJar) + pub.artifact(javadocJar) + pub.artifactId = "flywheel-${project.name}-${mcVersion}" } } } - static Configuration newConfiguration(Project project, String name) { - return project.configurations.create(name) { Configuration it -> + static NamedDomainObjectProvider newConfiguration(Project project, String name) { + return project.configurations.register(name) { Configuration it -> it.canBeConsumed = true it.canBeResolved = false } diff --git a/common/build.gradle b/common/build.gradle index 49290b0f8..66d8d4292 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -6,7 +6,7 @@ plugins { id 'flywheel.java' id 'flywheel.package-infos' id 'flywheel.subproject' - id 'flywheel.outgoing-configuration' + id 'flywheel.jar-sets' } sourceSets { @@ -40,30 +40,24 @@ sourceSets { } } -jar { - from sourceSets.api.output - from sourceSets.lib.output - from sourceSets.backend.output - archiveClassifier.set('') +// For sharing with other subprojects. +jarSets { + createJars('apiOnly', sourceSets.api).configure { + it.createOutgoingConfiguration('common') + } + createJars('lib').configure { + it.createOutgoingConfiguration('common') + } + createJars('backend').configure { + it.createOutgoingConfiguration('common') + } + createJars('impl', sourceSets.main).configure { + it.createOutgoingConfiguration('common') + } } -sourcesJar { - from sourceSets.api.allSource - from sourceSets.lib.allSource - from sourceSets.backend.allSource -} - -javadoc { - source sourceSets.api.allJava - source sourceSets.lib.allJava - source sourceSets.backend.allJava -} - -outgoing.createJarAndOutgoingConfiguration("apiOnly", sourceSets.api) -outgoing.createJarAndOutgoingConfiguration("lib") -def apiLibJar = outgoing.createJarAndOutgoingConfiguration("api", sourceSets.api, sourceSets.lib) -def backendJar = outgoing.createJarAndOutgoingConfiguration("backend") -def implJar = outgoing.createJarAndOutgoingConfiguration("impl", sourceSets.main) +// For publishing +def apiLibJar = jarSets.createJars('api', sourceSets.api, sourceSets.lib) dependencies { modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}" @@ -78,32 +72,16 @@ test { publishing { publications { register('mavenIntermediary', MavenPublication) { - from(components['java']) artifact apiLibJar.remapJar artifact apiLibJar.remapSources artifact apiLibJar.javadocJar - artifact backendJar.remapJar - artifact backendJar.remapSources - artifact backendJar.javadocJar - artifact implJar.remapJar - artifact implJar.remapSources - artifact implJar.javadocJar - artifactId = "flywheel-${project.name}-intermediary-${artifact_minecraft_version}" + artifactId = "flywheel-common-intermediary-api-${artifact_minecraft_version}" } register('mavenMojmap', MavenPublication) { - artifact jar - artifact sourcesJar - artifact javadocJar artifact apiLibJar.jar artifact apiLibJar.sources artifact apiLibJar.javadocJar - artifact backendJar.jar - artifact backendJar.sources - artifact backendJar.javadocJar - artifact implJar.jar - artifact implJar.sources - artifact implJar.javadocJar - artifactId = "flywheel-${project.name}-mojmap-${artifact_minecraft_version}" + artifactId = "flywheel-common-mojmap-api-${artifact_minecraft_version}" } } }