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 fea600095..0acac776d 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarSetExtension.kt @@ -24,6 +24,6 @@ open class JarSetExtension(private val project: Project) { val remapSourcesJarTask = project.tasks.named("remapSourcesJar") val javadocJarTask = project.tasks.named("javadocJar") - JarTaskSet(project, "main", jarTask, remapJarTask, sourcesJarTask, remapSourcesJarTask, javadocJarTask) + JarTaskSet(project, "main", jarTask, sourcesJarTask, javadocJarTask, remapJarTask, remapSourcesJarTask) } } 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 3e925626c..64bd88cbe 100644 --- a/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt +++ b/buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt @@ -18,16 +18,16 @@ import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.the class JarTaskSet( - val project: Project, - val name: String, - val jar: TaskProvider, - val remapJar: TaskProvider, - val sources: TaskProvider, - val remapSources: TaskProvider, - val javadocJar: TaskProvider + private val project: Project, + private val name: String, + private val jar: TaskProvider, + private val sources: TaskProvider, + private val javadocJar: TaskProvider, + private val remapJar: TaskProvider, + private val remapSources: TaskProvider ) { - fun publishRemap(artifactId: String) { + fun publish(artifactId: String) { project.the().publications { register("${name}RemapMaven") { artifact(remapJar) @@ -38,17 +38,9 @@ class JarTaskSet( } } - fun publish(artifactId: String) { - project.the().publications { - register("${name}Maven") { - artifact(jar) - artifact(sources) - artifact(javadocJar) - this.artifactId = artifactId - } - } - } - + /** + * Create a new configuration that can be consumed by other projects, and export the base jar. + */ fun createOutgoingConfiguration() { val config = project.configurations.register(name) { isCanBeConsumed = true @@ -58,24 +50,31 @@ class JarTaskSet( project.artifacts.add(config.name, jar) } - fun assembleRemaps() { + /** + * Configure the assemble task to depend on the remap tasks and javadoc jar. + */ + fun addToAssemble() { project.tasks.named("assemble").configure { dependsOn(remapJar, remapSources, javadocJar) } } - fun configureEach(action: Action) { - jar.configure(action) - sources.configure(action) - javadocJar.configure(action) - + /** + * Configure the remap tasks with the given action. + */ + fun configureRemap(action: Action) { remapJar.configure(action) remapSources.configure(action) } - fun configureRemap(action: Action) { - remapJar.configure(action) - remapSources.configure(action) + /** + * Create a new JarTaskSet with the same base jars but new tasks for remapping. + */ + fun forkRemap(newName: String): JarTaskSet { + val remapJarTask = createRemapJar(project, newName, jar) + val remapSourcesTask = createRemapSourcesJar(project, newName, sources) + + return JarTaskSet(project, newName, jar, sources, javadocJar, remapJarTask, remapSourcesTask) } companion object { @@ -103,29 +102,40 @@ class JarTaskSet( } fun create(project: Project, name: String, vararg sourceSetSet: SourceSet): JarTaskSet { - val buildDirectory = project.layout.buildDirectory - val devlibs = buildDirectory.dir("devlibs/${name}") - val libs = buildDirectory.dir("libs/${name}") + val jarTask = createJar(project, name, sourceSetSet) + val sourcesTask = createSourcesJar(project, name, sourceSetSet) + val javadocJarTask = createJavadocJar(project, name, sourceSetSet) + + val remapJarTask = createRemapJar(project, name, jarTask) + val remapSourcesTask = createRemapSourcesJar(project, name, sourcesTask) + + return JarTaskSet(project, name, jarTask, sourcesTask, javadocJarTask, remapJarTask, remapSourcesTask) + } - val jarTask = project.tasks.register("${name}Jar") { + private fun createJar( + project: Project, + name: String, + sourceSetSet: Array + ): TaskProvider { + return project.tasks.register("${name}Jar") { group = BUILD_GROUP - destinationDirectory.set(devlibs) + destinationDirectory.set(project.layout.buildDirectory.dir("devlibs/${name}")) for (set in sourceSetSet) { from(set.output) } excludeDuplicatePackageInfos(this) } - val remapJarTask = project.tasks.register("${name}RemapJar") { - dependsOn(jarTask) - group = LOOM_GROUP - destinationDirectory.set(libs) + } - inputFile.set(jarTask.flatMap { it.archiveFile }) - } - val sourcesTask = project.tasks.register("${name}SourcesJar") { + private fun createSourcesJar( + project: Project, + name: String, + sourceSetSet: Array + ): TaskProvider { + return project.tasks.register("${name}SourcesJar") { group = BUILD_GROUP - destinationDirectory.set(devlibs) + destinationDirectory.set(project.layout.buildDirectory.dir("devlibs/${name}")) archiveClassifier.set(SOURCES_CLASSIFIER) for (set in sourceSetSet) { @@ -133,17 +143,16 @@ class JarTaskSet( } excludeDuplicatePackageInfos(this) } - val remapSourcesTask = project.tasks.register("${name}RemapSourcesJar") { - dependsOn(sourcesTask) - group = LOOM_GROUP - destinationDirectory.set(libs) - archiveClassifier.set(SOURCES_CLASSIFIER) + } - inputFile.set(sourcesTask.flatMap { it.archiveFile }) - } + private fun createJavadocJar( + project: Project, + name: String, + sourceSetSet: Array + ): TaskProvider { val javadocTask = project.tasks.register("${name}Javadoc") { group = BUILD_GROUP - setDestinationDir(buildDirectory.dir("docs/${name}-javadoc").get().asFile) + setDestinationDir(project.layout.buildDirectory.dir("docs/${name}-javadoc").get().asFile) for (set in sourceSetSet) { source(set.allJava) @@ -151,16 +160,43 @@ class JarTaskSet( } excludeDuplicatePackageInfos(this) } - val javadocJarTask = project.tasks.register("${name}JavadocJar") { + return project.tasks.register("${name}JavadocJar") { dependsOn(javadocTask) group = BUILD_GROUP - destinationDirectory.set(libs) + destinationDirectory.set(project.layout.buildDirectory.dir("libs/${name}")) archiveClassifier.set(JAVADOC_CLASSIFIER) from(javadocTask.map { it.outputs }) } + } - return JarTaskSet(project, name, jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask) + private fun createRemapJar( + project: Project, + name: String, + jar: TaskProvider + ): TaskProvider { + return project.tasks.register("${name}RemapJar") { + dependsOn(jar) + group = LOOM_GROUP + destinationDirectory.set(project.layout.buildDirectory.dir("libs/${name}")) + + inputFile.set(jar.flatMap { it.archiveFile }) + } + } + + private fun createRemapSourcesJar( + project: Project, + name: String, + jar: TaskProvider + ): TaskProvider { + return project.tasks.register("${name}RemapSourcesJar") { + dependsOn(jar) + group = LOOM_GROUP + destinationDirectory.set(project.layout.buildDirectory.dir("libs/${name}")) + archiveClassifier.set(SOURCES_CLASSIFIER) + + inputFile.set(jar.flatMap { it.archiveFile }) + } } } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index cd4b81ca1..cb95861de 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -46,8 +46,20 @@ jarSets { // 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")}") + addToAssemble() + publish("flywheel-common-intermediary-api-${property("artifact_minecraft_version")}") + + // Don't publish the un-remapped jars because they don't have the correct manifest populated by Loom. + forkRemap("apiMojmap").apply { + addToAssemble() + configureRemap { + // "named" == mojmap + // We're probably remapping from named to named so Loom should noop this. + targetNamespace = "named" + } + + publish("flywheel-common-mojmap-api-${property("artifact_minecraft_version")}") + } } } diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 131955622..1d1c8e8c6 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -43,8 +43,11 @@ platform { } jarSets { - mainSet.publishRemap(platform.modArtifactId) - create("api", api, lib).publishRemap(platform.apiArtifactId) + mainSet.publish(platform.modArtifactId) + create("api", api, lib).apply { + addToAssemble() + publish(platform.apiArtifactId) + } } defaultPackageInfos { diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 8393ade99..49359a794 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -43,8 +43,11 @@ platform { } jarSets { - mainSet.publishRemap(platform.modArtifactId) - create("api", api, lib).publishRemap(platform.apiArtifactId) + mainSet.publish(platform.modArtifactId) + create("api", api, lib).apply { + addToAssemble() + publish(platform.apiArtifactId) + } } defaultPackageInfos {