Skip to content

Commit f01c143

Browse files
build: Apply convention plugins per module instead of the root subprojects block (#6354)
* build: Apply convention plugins per module instead of the root subprojects block * docs: Add AndroidX MavenUploadHelper to third-party notices --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent fc3cbaa commit f01c143

101 files changed

Lines changed: 500 additions & 191 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎THIRD_PARTY_NOTICES.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,34 @@ limitations under the License.
390390

391391
---
392392

393+
## Android Open Source Project — AndroidX MavenUploadHelper (Apache 2.0)
394+
395+
**Source:** https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549<br>
396+
**License:** Apache License 2.0<br>
397+
**Copyright:** Copyright 2018 The Android Open Source Project
398+
399+
### Scope
400+
401+
The Sentry Java SDK build includes an adapted version of the AndroidX build's POM rewriting, which adds `<type>aar</type>` to dependencies on Android libraries in published POMs. The code resides in the build logic at `build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt` and is not part of the published artifacts.
402+
403+
```
404+
Copyright 2018 The Android Open Source Project
405+
406+
Licensed under the Apache License, Version 2.0 (the "License");
407+
you may not use this file except in compliance with the License.
408+
You may obtain a copy of the License at
409+
410+
http://www.apache.org/licenses/LICENSE-2.0
411+
412+
Unless required by applicable law or agreed to in writing, software
413+
distributed under the License is distributed on an "AS IS" BASIS,
414+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
415+
See the License for the specific language governing permissions and
416+
limitations under the License.
417+
```
418+
419+
---
420+
393421
## OpenTelemetry (Apache 2.0)
394422

395423
**Source:** https://github.com/open-telemetry/opentelemetry-java (Commit: 0aacc55d1e3f5cc6dbb4f8fa26bcb657b01a7bc9)<br>

‎build-logic/build.gradle.kts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ plugins {
55
dependencies {
66
implementation(libs.animalsniffer.gradle.plugin)
77
implementation(libs.spotlessLib)
8+
implementation(libs.detektLib)
9+
implementation(libs.vanniktechMavenPublishLib)
810
implementation(libs.asm)
911
compileOnly(libs.kotlin.gradle.plugin)
1012
compileOnly(libs.android.gradle.plugin)
@@ -16,6 +18,18 @@ gradlePlugin {
1618
id = "io.sentry.jdk-target"
1719
implementationClass = "io.sentry.gradle.JdkTargetConvention"
1820
}
21+
register("sentryDetekt") {
22+
id = "io.sentry.detekt"
23+
implementationClass = "io.sentry.gradle.SentryDetektPlugin"
24+
}
25+
register("sentryPublish") {
26+
id = "io.sentry.publish"
27+
implementationClass = "io.sentry.gradle.SentryPublishPlugin"
28+
}
29+
register("sentryMultiplatformPublish") {
30+
id = "io.sentry.publish.multiplatform"
31+
implementationClass = "io.sentry.gradle.SentryMultiplatformPublishPlugin"
32+
}
1933
register("sentryApiValidation") {
2034
id = "io.sentry.api-validation"
2135
implementationClass = "io.sentry.gradle.SentryApiValidationPlugin"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
3+
*
4+
* Copyright 2018 The Android Open Source Project
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package io.sentry.gradle
20+
21+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
22+
import groovy.util.Node
23+
24+
private val androidLibs =
25+
setOf(
26+
"sentry-android-core",
27+
"sentry-android-ndk",
28+
"sentry-android-fragment",
29+
"sentry-android-navigation",
30+
"sentry-android-navigation3",
31+
"sentry-android-timber",
32+
"sentry-compose-android",
33+
"sentry-android-sqlite",
34+
"sentry-android-replay",
35+
)
36+
37+
private val androidXLibs = listOf("androidx.core:core")
38+
39+
// Workaround for https://github.com/gradle/gradle/issues/3170
40+
fun MavenPublishBaseExtension.assignAarTypes() {
41+
pom {
42+
withXml {
43+
val dependencies =
44+
asNode().children().find { it is Node && it.name().toString().endsWith("dependencies") }
45+
as Node?
46+
47+
dependencies?.children()?.forEach { dep ->
48+
if (dep !is Node) {
49+
return@forEach
50+
}
51+
val group =
52+
dep.children().firstOrNull { it is Node && it.name().toString().endsWith("groupId") }
53+
as? Node
54+
val groupValue = group?.children()?.firstOrNull() as? String
55+
56+
val artifactId =
57+
dep.children().firstOrNull { it is Node && it.name().toString().endsWith("artifactId") }
58+
as? Node
59+
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String
60+
61+
if (artifactIdValue in androidLibs) {
62+
dep.appendNode("type", "aar")
63+
} else if ("$groupValue:$artifactIdValue" in androidXLibs) {
64+
dep.appendNode("type", "aar")
65+
}
66+
}
67+
}
68+
}
69+
}

buildSrc/src/main/java/Publication.kt renamed to build-logic/src/main/kotlin/io/sentry/gradle/Publication.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package io.sentry.gradle
2+
13
import org.gradle.api.Project
24
import org.gradle.api.distribution.DistributionContainer
35
import org.gradle.api.file.CopySpec
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.sentry.gradle
2+
3+
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
import org.gradle.kotlin.dsl.configure
7+
8+
/** Runs detekt on a module against the shared ruleset, with a per-module baseline. */
9+
class SentryDetektPlugin : Plugin<Project> {
10+
override fun apply(project: Project) {
11+
project.pluginManager.apply("io.gitlab.arturbosch.detekt")
12+
13+
project.extensions.configure<DetektExtension> {
14+
buildUponDefaultConfig = true
15+
allRules = true
16+
config.setFrom(project.isolated.rootProject.projectDirectory.file("detekt.yml"))
17+
baseline = project.file("detekt-baseline.xml")
18+
}
19+
}
20+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package io.sentry.gradle
2+
3+
import com.vanniktech.maven.publish.JavaLibrary
4+
import com.vanniktech.maven.publish.JavadocJar
5+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
6+
import java.io.File
7+
import org.gradle.api.Plugin
8+
import org.gradle.api.Project
9+
import org.gradle.api.distribution.DistributionContainer
10+
import org.gradle.api.distribution.plugins.DistributionPlugin
11+
import org.gradle.api.plugins.JavaPluginExtension
12+
import org.gradle.api.publish.PublishingExtension
13+
import org.gradle.kotlin.dsl.configure
14+
15+
/** Publishes a JVM or Android module and packages it as the zip distribution craft consumes. */
16+
class SentryPublishPlugin : Plugin<Project> {
17+
override fun apply(project: Project) {
18+
project.configurePublishing(DistributionContainer::configureForJvm)
19+
}
20+
}
21+
22+
/**
23+
* Publishes a Kotlin Multiplatform module. Separate from [SentryPublishPlugin] because the
24+
* per-target distributions it lays out have no counterpart in a single-target module.
25+
*/
26+
class SentryMultiplatformPublishPlugin : Plugin<Project> {
27+
override fun apply(project: Project) {
28+
project.configurePublishing(DistributionContainer::configureForMultiplatform)
29+
}
30+
}
31+
32+
private fun Project.configurePublishing(
33+
configureDistributions: DistributionContainer.(Project) -> Unit
34+
) {
35+
pluginManager.apply(DistributionPlugin::class.java)
36+
pluginManager.apply("com.vanniktech.maven.publish")
37+
38+
extensions.configure<DistributionContainer> {
39+
configureDistributions(project)
40+
// craft only uses zip archives
41+
forEach { dist ->
42+
if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) {
43+
tasks.named("distTar").configure { enabled = false }
44+
} else {
45+
tasks.named(dist.name + "DistTar").configure { enabled = false }
46+
}
47+
}
48+
}
49+
50+
val sep = File.separator
51+
val distributionFile =
52+
layout.buildDirectory.file("distributions$sep$name-$version.zip").get().asFile
53+
54+
tasks.named("distZip").configure {
55+
dependsOn("publishToMavenLocal")
56+
dependsOn("publishAllPublicationsTo${DIST_MAVEN_REPO.replaceFirstChar { it.uppercase() }}Repository")
57+
val file = distributionFile
58+
doLast {
59+
if (!file.exists()) {
60+
throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
61+
}
62+
if (file.length() == 0L) {
63+
throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
64+
}
65+
}
66+
}
67+
68+
extensions.configure<MavenPublishBaseExtension> { assignAarTypes() }
69+
70+
plugins.withId("java-library") {
71+
extensions.configure<MavenPublishBaseExtension> {
72+
// we have to disable javadoc publication in maven-publish plugin as it's not
73+
// including it in the .module file
74+
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861
75+
// and do it ourselves
76+
configure(JavaLibrary(JavadocJar.None(), sourcesJar = true))
77+
}
78+
79+
extensions.configure<JavaPluginExtension> { withJavadocJar() }
80+
}
81+
82+
extensions.configure<PublishingExtension> {
83+
// the dist zips craft publishes are assembled from this, see Publication.kt
84+
repositories.maven {
85+
name = DIST_MAVEN_REPO
86+
url = distMavenDir.get().asFile.toURI()
87+
}
88+
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
89+
repositories.maven {
90+
name = "unityMaven"
91+
url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI()
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)