Skip to content

Commit a29ab32

Browse files
romtsnclaude
andauthored
build: Assemble dist zips from a local Maven repo layout (#6467)
* build: Assemble dist zips from a local Maven repo layout Craft expects Maven file names in each dist dir, e.g. <artifactId>-<version>-javadoc.jar. We used to copy build outputs and rename them to match, so the rules broke whenever a plugin changed its output names. The vanniktech maven-publish 0.30.0 -> 0.37.0 bump (#6412) added the version to the KMP javadoc jars, so sentry-compose-<version>-javadoc.jar was missing and the 8.63.0 publish failed. Now every module also publishes to build/distMaven and the dist zips copy from its Maven layout, where file names are fixed by Maven itself. Only the craft-specific names are renamed (pom-default.xml, -release.aar). The zip contents are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(build): Make distMavenDir an extension property Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 174d531 commit a29ab32

2 files changed

Lines changed: 42 additions & 90 deletions

File tree

‎build.gradle.kts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ subprojects {
9999

100100
tasks.named("distZip").configure {
101101
this.dependsOn("publishToMavenLocal")
102+
this.dependsOn("publishAllPublicationsTo${DIST_MAVEN_REPO.replaceFirstChar { it.uppercase() }}Repository")
102103
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
103104
this.doLast {
104105
if (!file.exists()) throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
@@ -129,6 +130,11 @@ subprojects {
129130
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
130131
configure<PublishingExtension> {
131132
repositories {
133+
// the dist zips craft publishes are assembled from this, see Publication.kt
134+
maven {
135+
name = DIST_MAVEN_REPO
136+
url = distMavenDir.get().asFile.toURI()
137+
}
132138
maven {
133139
name = "unityMaven"
134140
url = rootProject.layout.buildDirectory.file("unityMaven").get().asFile.toURI()
Lines changed: 36 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,56 @@
11
import org.gradle.api.Project
22
import org.gradle.api.distribution.DistributionContainer
33
import org.gradle.api.file.CopySpec
4-
import java.io.File
4+
import org.gradle.api.file.Directory
5+
import org.gradle.api.provider.Provider
56

6-
private object Consts {
7-
val taskRegex = Regex("(.*)DistZip")
8-
}
7+
/**
8+
* Name of the per-project Maven repository the dist zips are assembled from.
9+
* `distZip` depends on `publishAllPublicationsToDistMavenRepository`.
10+
*/
11+
const val DIST_MAVEN_REPO = "distMaven"
12+
13+
val Project.distMavenDir: Provider<Directory> get() = layout.buildDirectory.dir(DIST_MAVEN_REPO)
914

1015
private fun Project.versionName(): String =
1116
providers.gradleProperty("versionName").get()
1217

1318
// configure distZip tasks for multiplatform
1419
fun DistributionContainer.configureForMultiplatform(project: Project) {
15-
val sep = File.separator
16-
val version = project.versionName()
17-
val name = project.name
18-
19-
this.maybeCreate("android").contents {
20-
from("build${sep}publications${sep}androidRelease") {
21-
renameModule(name, "android", version = version)
22-
}
23-
from("build${sep}outputs${sep}aar") {
24-
include("*-release*")
25-
rename {
26-
it.replace("-release", "-android-release")
27-
}
28-
}
29-
from("build${sep}libs") {
30-
include("*android*")
31-
include("*androidRelease-javadoc*")
32-
rename {
33-
it.replace("androidRelease-javadoc", "android")
34-
}
35-
}
36-
}
37-
this.getByName("main").contents {
38-
from("build${sep}publications${sep}kotlinMultiplatform") {
39-
renameModule(name, version = version)
40-
}
41-
from("build${sep}kotlinToolingMetadata")
42-
from("build${sep}libs") {
43-
include("*compose-kotlin*")
44-
include("*compose-metadata*")
45-
rename {
46-
it.replace("-kotlin", "")
47-
.replace("-metadata", "")
48-
.replace("Multiplatform-javadoc", "")
49-
}
50-
}
51-
}
52-
this.maybeCreate("desktop").contents {
53-
// kotlin multiplatform modules
54-
from("build${sep}publications${sep}desktop") {
55-
renameModule(name, "desktop", version = version)
56-
}
57-
from("build${sep}libs") {
58-
include("*desktop*")
59-
include("*desktop-javadoc*")
60-
rename {
61-
it.replace("desktop-javadoc", "desktop")
62-
}
63-
}
64-
}
20+
getByName("main").contents { fromDistMaven(project, project.name) }
21+
maybeCreate("android").contents { fromDistMaven(project, "${project.name}-android") }
22+
maybeCreate("desktop").contents { fromDistMaven(project, "${project.name}-desktop") }
6523

6624
// make other distZip tasks run together with the main distZip
67-
val platformDists = project.tasks.filter { task ->
68-
task.name.matches(Consts.taskRegex)
69-
}.toTypedArray()
25+
val platformDists = project.tasks.filter { it.name.matches(Regex("(.*)DistZip")) }.toTypedArray()
7026
project.tasks.getByName("distZip").finalizedBy(*platformDists)
7127
}
7228

7329
fun DistributionContainer.configureForJvm(project: Project) {
74-
val sep = File.separator
75-
val version = project.versionName()
76-
val name = project.name
77-
78-
this.getByName("main").contents {
79-
// non android modules
80-
from("build${sep}libs")
81-
from("build${sep}publications${sep}maven") {
82-
renameModule(name, version = version)
83-
}
84-
// android modules
85-
from("build${sep}outputs${sep}aar") {
86-
include("*-release*")
87-
}
88-
from("build${sep}publications${sep}release") {
89-
renameModule(name, version = version)
90-
}
91-
from("build${sep}intermediates${sep}java_doc_jar${sep}release") {
92-
include("*javadoc*")
93-
rename { it.replace("release", "$name-$version") }
94-
}
95-
from("build${sep}intermediates${sep}source_jar${sep}release") {
96-
include("*sources*")
97-
rename { it.replace("release", "$name-$version") }
98-
}
99-
}
30+
getByName("main").contents { fromDistMaven(project, project.name) }
10031
}
10132

102-
private fun CopySpec.renameModule(projectName: String, renameTo: String = "", version: String) {
103-
var target = ""
104-
if (renameTo.isNotEmpty()) {
105-
target = "-$renameTo"
106-
}
107-
rename {
108-
it.replace("module.json", "$projectName$target-$version.module")
33+
/**
34+
* Copies one publication out of the project's Maven repository layout. Maven guarantees file names
35+
* there (`<artifactId>-<version>[-<classifier>].<ext>`) independently of how the publish plugin
36+
* names its tasks or intermediate outputs, which is exactly what craft expects. Only the few
37+
* craft-specific names below need renaming.
38+
*/
39+
private fun CopySpec.fromDistMaven(project: Project, artifactId: String) {
40+
val version = project.versionName()
41+
val groupPath = project.group.toString().replace('.', '/')
42+
from(project.distMavenDir.map { it.dir("$groupPath/$artifactId/$version") }) {
43+
exclude("*.md5", "*.sha1", "*.sha256", "*.sha512", "*.asc")
44+
rename {
45+
when (it) {
46+
// craft reads the POM from a fixed name
47+
"$artifactId-$version.pom" -> "pom-default.xml"
48+
// craft's android config maps <dir>-<version> to <dir>-release.aar
49+
"$artifactId-$version.aar" -> "$artifactId-release.aar"
50+
// kept for parity with the old layout
51+
"$artifactId-$version-kotlin-tooling-metadata.json" -> "kotlin-tooling-metadata.json"
52+
else -> it
53+
}
54+
}
10955
}
11056
}

0 commit comments

Comments
 (0)