Skip to content

Commit

Permalink
Aven-jars assemble
Browse files Browse the repository at this point in the history
- Create separate remap tasks for the common mojmap api to get loom to
  populate its manifest file
- Add helper method to fork a JarTaskSet and generate new remap tasks
- Remove non-remap publish method
- Set assemble to depend on published jar tasks again
- Add companion methods to create individual jar tasks
  • Loading branch information
Jozufozu committed May 4, 2024
1 parent bba587f commit 83d0934
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ open class JarSetExtension(private val project: Project) {
val remapSourcesJarTask = project.tasks.named<RemapSourcesJarTask>("remapSourcesJar")
val javadocJarTask = project.tasks.named<Jar>("javadocJar")

JarTaskSet(project, "main", jarTask, remapJarTask, sourcesJarTask, remapSourcesJarTask, javadocJarTask)
JarTaskSet(project, "main", jarTask, sourcesJarTask, javadocJarTask, remapJarTask, remapSourcesJarTask)
}
}
140 changes: 88 additions & 52 deletions buildSrc/src/main/kotlin/com/jozufozu/gradle/jarset/JarTaskSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Jar>,
val remapJar: TaskProvider<RemapJarTask>,
val sources: TaskProvider<Jar>,
val remapSources: TaskProvider<RemapSourcesJarTask>,
val javadocJar: TaskProvider<Jar>
private val project: Project,
private val name: String,
private val jar: TaskProvider<Jar>,
private val sources: TaskProvider<Jar>,
private val javadocJar: TaskProvider<Jar>,
private val remapJar: TaskProvider<RemapJarTask>,
private val remapSources: TaskProvider<RemapSourcesJarTask>
) {

fun publishRemap(artifactId: String) {
fun publish(artifactId: String) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${name}RemapMaven") {
artifact(remapJar)
Expand All @@ -38,17 +38,9 @@ class JarTaskSet(
}
}

fun publish(artifactId: String) {
project.the<PublishingExtension>().publications {
register<MavenPublication>("${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
Expand All @@ -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>) {
jar.configure(action)
sources.configure(action)
javadocJar.configure(action)

/**
* Configure the remap tasks with the given action.
*/
fun configureRemap(action: Action<AbstractRemapJarTask>) {
remapJar.configure(action)
remapSources.configure(action)
}

fun configureRemap(action: Action<AbstractRemapJarTask>) {
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 {
Expand Down Expand Up @@ -103,64 +102,101 @@ 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<Jar>("${name}Jar") {
private fun createJar(
project: Project,
name: String,
sourceSetSet: Array<out SourceSet>
): TaskProvider<Jar> {
return project.tasks.register<Jar>("${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<RemapJarTask>("${name}RemapJar") {
dependsOn(jarTask)
group = LOOM_GROUP
destinationDirectory.set(libs)
}

inputFile.set(jarTask.flatMap { it.archiveFile })
}
val sourcesTask = project.tasks.register<Jar>("${name}SourcesJar") {
private fun createSourcesJar(
project: Project,
name: String,
sourceSetSet: Array<out SourceSet>
): TaskProvider<Jar> {
return project.tasks.register<Jar>("${name}SourcesJar") {
group = BUILD_GROUP
destinationDirectory.set(devlibs)
destinationDirectory.set(project.layout.buildDirectory.dir("devlibs/${name}"))
archiveClassifier.set(SOURCES_CLASSIFIER)

for (set in sourceSetSet) {
from(set.allSource)
}
excludeDuplicatePackageInfos(this)
}
val remapSourcesTask = project.tasks.register<RemapSourcesJarTask>("${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<out SourceSet>
): TaskProvider<Jar> {
val javadocTask = project.tasks.register<Javadoc>("${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)
classpath += set.compileClasspath
}
excludeDuplicatePackageInfos(this)
}
val javadocJarTask = project.tasks.register<Jar>("${name}JavadocJar") {
return project.tasks.register<Jar>("${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<Jar>
): TaskProvider<RemapJarTask> {
return project.tasks.register<RemapJarTask>("${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<Jar>
): TaskProvider<RemapSourcesJarTask> {
return project.tasks.register<RemapSourcesJarTask>("${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 })
}
}
}
}
16 changes: 14 additions & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")}")
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83d0934

Please sign in to comment.