Skip to content

Commit 0a7ac5a

Browse files
authored
Update distZip task to use the locally published artifacts via publishToMavenLocal (#425)
* Update * Update * Update * Let CI run for testing * Update * Update * Update * Update * Update * Clean up * Update use maybeCreate always
1 parent d75f8f2 commit 0a7ac5a

File tree

3 files changed

+48
-220
lines changed

3 files changed

+48
-220
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Internal
6+
7+
- Update `distZip` task to use the locally published artifacts via `publishToMavenLocal` ([#425](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/425))
8+
39
## 0.15.0
410

511
### Enhancements

build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ subprojects {
3131
apply<DistributionPlugin>()
3232

3333
val sep = File.separator
34+
// The path where we want publishToMavenLocal to output the artifacts to
35+
val buildPublishDir = "${project.layout.buildDirectory.get().asFile.path}${sep}sentry-local-publish$sep"
3436

3537
configure<DistributionContainer> {
36-
this.configureForMultiplatform(this@subprojects)
38+
configureForMultiplatform(this@subprojects, buildPublishDir)
3739
}
3840

3941
tasks.named("distZip").configure {
40-
this.dependsOn("publishToMavenLocal")
41-
this.doLast {
42+
System.setProperty("maven.repo.local", buildPublishDir)
43+
dependsOn("publishToMavenLocal")
44+
doLast {
4245
val distributionFilePath =
43-
"${this.project.buildDir}${sep}distributions${sep}${this.project.name}-${this.project.version}.zip"
46+
"${project.layout.buildDirectory.get().asFile.path}${sep}distributions${sep}${project.name}-${project.version}.zip"
4447
val file = File(distributionFilePath)
4548
if (!file.exists()) throw GradleException("Distribution file: $distributionFilePath does not exist")
4649
if (file.length() == 0L) throw GradleException("Distribution file: $distributionFilePath is empty")

buildSrc/src/main/java/Publication.kt

Lines changed: 35 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -1,228 +1,47 @@
1+
import org.gradle.api.GradleException
12
import org.gradle.api.Project
23
import org.gradle.api.distribution.DistributionContainer
3-
import org.gradle.api.file.CopySpec
44
import java.io.File
55

6-
val sep: String = File.separator
6+
private val sep: String = File.separator
77

8-
// configure distZip tasks for multiplatform
9-
fun DistributionContainer.configureForMultiplatform(project: Project) {
10-
val version = project.properties["versionName"].toString()
11-
this.getByName("main").contents {
12-
from("build${sep}publications${sep}kotlinMultiplatform") {
13-
renameModule(project.name, version = version)
14-
}
15-
// The current Kotlin version doesn't generate this *-all.jar anymore.
16-
// This is a placeholder for backwards compatibility with craft until we fix it there directly.
17-
from("build${sep}libs") {
18-
include("${project.name}-metadata-$version*")
19-
rename {
20-
it.replace("metadata-$version", "$version-all")
21-
}
22-
}
23-
from("build${sep}kotlinToolingMetadata") {
24-
rename {
25-
it.replace(
26-
"kotlin-tooling-metadata.json",
27-
"${project.name}-$version-kotlin-tooling-metadata.json"
28-
)
29-
}
30-
}
31-
from("build${sep}libs") {
32-
include("${project.name}-kotlin*")
33-
include("${project.name}-metadata*")
34-
withJavadoc(project.name)
35-
rename {
36-
it.replace("multiplatform-kotlin", "multiplatform").replace("-metadata", "")
37-
}
38-
}
39-
}
40-
this.maybeCreate("android").contents {
41-
from("build${sep}publications${sep}androidRelease") {
42-
renameModule(project.name, "android", version)
43-
}
44-
from("build${sep}outputs${sep}aar${sep}${project.name}-release.aar") {
45-
rename {
46-
it.replace("-release", "-android-release")
47-
}
48-
}
49-
from("build${sep}libs") {
50-
include("*android*")
51-
withJavadoc(project.name, "android")
52-
}
53-
}
54-
this.maybeCreate("jvm").contents {
55-
from("build${sep}publications${sep}jvm") {
56-
renameModule(project.name, "jvm", version)
57-
}
58-
from("build${sep}libs$sep") {
59-
include("*jvm*")
60-
withJavadoc(project.name, "jvm")
61-
}
62-
}
63-
this.maybeCreate("iosarm64").contents {
64-
from("build${sep}publications${sep}iosArm64") {
65-
renameModule(project.name, "iosarm64", version)
66-
}
67-
from("build${sep}libs$sep") {
68-
include("${project.name}-iosarm64*")
69-
withJavadoc(project.name, "iosarm64")
70-
}
71-
fromKlib(project.name, "iosArm64", version)
72-
}
73-
this.maybeCreate("iosx64").contents {
74-
from("build${sep}publications${sep}iosX64") {
75-
renameModule(project.name, "iosx64", version)
76-
}
77-
from("build${sep}libs$sep") {
78-
include("${project.name}-iosx64*")
79-
withJavadoc(project.name, "iosx64")
80-
}
81-
fromKlib(project.name, "iosX64", version)
82-
}
83-
this.maybeCreate("iossimulatorarm64").contents {
84-
from("build${sep}publications${sep}iosSimulatorArm64") {
85-
renameModule(project.name, "iossimulatorarm64", version)
86-
}
87-
from("build${sep}libs$sep") {
88-
include("${project.name}-iossimulatorarm64*")
89-
withJavadoc(project.name, "iossimulatorarm64")
90-
}
91-
fromKlib(project.name, "iosSimulatorArm64", version)
92-
}
93-
this.maybeCreate("macosarm64").contents {
94-
from("build${sep}publications${sep}macosArm64") {
95-
renameModule(project.name, "macosarm64", version)
96-
}
97-
from("build${sep}libs$sep") {
98-
include("${project.name}-macosarm64*")
99-
withJavadoc(project.name, "macosarm64")
100-
}
101-
fromKlib(project.name, "macosArm64", version)
102-
}
103-
this.maybeCreate("macosx64").contents {
104-
from("build${sep}publications${sep}macosX64") {
105-
renameModule(project.name, "macosx64", version)
106-
}
107-
from("build${sep}libs$sep") {
108-
include("${project.name}-macosx64*")
109-
withJavadoc(project.name, "macosx64")
110-
}
111-
fromKlib(project.name, "macosX64", version)
112-
}
113-
this.maybeCreate("watchosx64").contents {
114-
from("build${sep}publications${sep}watchosX64") {
115-
renameModule(project.name, "watchosx64", version)
116-
}
117-
from("build${sep}libs$sep") {
118-
include("${project.name}-watchosx64*")
119-
withJavadoc(project.name, "watchosx64")
120-
}
121-
fromKlib(project.name, "watchosX64", version)
122-
}
123-
this.maybeCreate("watchosarm32").contents {
124-
from("build${sep}publications${sep}watchosArm32") {
125-
renameModule(project.name, "watchosarm32", version)
126-
}
127-
from("build${sep}libs$sep") {
128-
include("${project.name}-watchosarm32*")
129-
withJavadoc(project.name, "watchosarm32")
130-
}
131-
fromKlib(project.name, "watchosArm32", version)
132-
}
133-
this.maybeCreate("watchosarm64").contents {
134-
from("build${sep}publications${sep}watchosArm64") {
135-
renameModule(project.name, "watchosarm64", version)
136-
}
137-
from("build${sep}libs$sep") {
138-
include("${project.name}-watchosarm64*")
139-
withJavadoc(project.name, "watchosarm64")
140-
}
141-
fromKlib(project.name, "watchosArm64", version)
142-
}
143-
this.maybeCreate("watchossimulatorarm64").contents {
144-
from("build${sep}publications${sep}watchosSimulatorArm64") {
145-
renameModule(project.name, "watchossimulatorarm64", version)
146-
}
147-
from("build${sep}libs$sep") {
148-
include("${project.name}-watchossimulatorarm64*")
149-
withJavadoc(project.name, "watchossimulatorarm64")
150-
}
151-
fromKlib(project.name, "watchosSimulatorArm64", version)
152-
}
153-
this.maybeCreate("tvosarm64").contents {
154-
from("build${sep}publications${sep}tvosArm64") {
155-
renameModule(project.name, "tvosarm64", version)
156-
}
157-
from("build${sep}libs$sep") {
158-
include("${project.name}-tvosarm64*")
159-
withJavadoc(project.name, "tvosarm64")
160-
}
161-
fromKlib(project.name, "tvosArm64", version)
162-
}
163-
this.maybeCreate("tvosx64").contents {
164-
from("build${sep}publications${sep}tvosX64") {
165-
renameModule(project.name, "tvosx64", version)
166-
}
167-
from("build${sep}libs$sep") {
168-
include("${project.name}-tvosx64*")
169-
withJavadoc(project.name, "tvosx64")
170-
}
171-
fromKlib(project.name, "tvosX64", version)
172-
}
173-
this.maybeCreate("tvossimulatorarm64").contents {
174-
from("build${sep}publications${sep}tvosSimulatorArm64") {
175-
renameModule(project.name, "tvossimulatorarm64", version)
176-
}
177-
from("build${sep}libs$sep") {
178-
include("${project.name}-tvossimulatorarm64*")
179-
withJavadoc(project.name, "tvossimulatorarm64")
180-
}
181-
fromKlib(project.name, "tvosSimulatorArm64", version)
182-
}
183-
}
8+
fun DistributionContainer.configureForMultiplatform(project: Project, buildPublishDir: String) {
9+
val version = project.property("versionName").toString()
10+
if (version.isEmpty()) {
11+
throw GradleException("DistZip: version name is empty")
12+
}
13+
val projectName = project.name
14+
val platforms = mapOf(
15+
"main" to projectName,
16+
"android" to "$projectName-android",
17+
"jvm" to "$projectName-jvm",
18+
"iosarm64" to "$projectName-iosarm64",
19+
"iossimulatorarm64" to "$projectName-iossimulatorarm64",
20+
"iosx64" to "$projectName-iosx64",
21+
"macosarm64" to "$projectName-macosarm64",
22+
"macosx64" to "$projectName-macosx64",
23+
"tvosarm64" to "$projectName-tvosarm64",
24+
"tvossimulatorarm64" to "$projectName-tvossimulatorarm64",
25+
"tvosx64" to "$projectName-tvosx64",
26+
"watchosarm32" to "$projectName-watchosarm32",
27+
"watchosarm64" to "$projectName-watchosarm64",
28+
"watchossimulatorarm64" to "$projectName-watchossimulatorarm64",
29+
"watchosx64" to "$projectName-watchosx64"
30+
)
18431

185-
private fun CopySpec.fromKlib(projectName: String, target: String, version: String) {
186-
val pos = projectName.length
187-
from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}cinterop") {
188-
include("*.klib")
189-
rename {
190-
it.replaceRange(pos, pos, "-${target.lowercase()}-$version")
191-
}
192-
}
193-
from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}klib") {
194-
rename {
195-
"$projectName-${target.lowercase()}-$version.klib"
196-
}
197-
}
198-
}
32+
platforms.forEach { (distName, projectName) ->
33+
val distribution = maybeCreate(distName)
34+
distribution.contents {
35+
val basePath = "${buildPublishDir}io${sep}sentry${sep}$projectName$sep$version"
19936

200-
private fun CopySpec.renameModule(projectName: String, renameTo: String = "", version: String) {
201-
var target = ""
202-
if (renameTo.isNotEmpty()) {
203-
target = "-$renameTo"
204-
}
205-
rename {
206-
it.replace("module.json", "$projectName$target-$version.module")
207-
}
208-
}
37+
// Rename the POM since craft looks for pom-default.xml
38+
from("$basePath$sep$projectName-$version.pom") {
39+
rename { "pom-default.xml" }
40+
}
20941

210-
private fun CopySpec.withJavadoc(projectName: String, renameTo: String = "") {
211-
include("*javadoc*")
212-
rename { fileName ->
213-
when {
214-
"javadoc" in fileName -> {
215-
val newName = buildString {
216-
append(fileName.substring(0, projectName.length))
217-
if (renameTo.isNotEmpty()) {
218-
append('-')
219-
append(renameTo)
220-
}
221-
append(fileName.substring(projectName.length))
222-
}
223-
newName
42+
from(basePath) {
43+
exclude("*.pom")
22444
}
225-
else -> fileName
22645
}
22746
}
22847
}

0 commit comments

Comments
 (0)