Skip to content

Commit 514edd5

Browse files
committed
build: Apply convention plugins per module instead of the root subprojects block
1 parent eb32cb5 commit 514edd5

101 files changed

Lines changed: 468 additions & 185 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.

‎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
compileOnly(libs.kotlin.gradle.plugin)
911
compileOnly(libs.android.gradle.plugin)
1012
}
@@ -15,6 +17,18 @@ gradlePlugin {
1517
id = "io.sentry.jdk-target"
1618
implementationClass = "io.sentry.gradle.JdkTargetConvention"
1719
}
20+
register("sentryDetekt") {
21+
id = "io.sentry.detekt"
22+
implementationClass = "io.sentry.gradle.SentryDetektPlugin"
23+
}
24+
register("sentryPublish") {
25+
id = "io.sentry.publish"
26+
implementationClass = "io.sentry.gradle.SentryPublishPlugin"
27+
}
28+
register("sentryMultiplatformPublish") {
29+
id = "io.sentry.publish.multiplatform"
30+
implementationClass = "io.sentry.gradle.SentryMultiplatformPublishPlugin"
31+
}
1832
register("sentryAnimalSniffer") {
1933
id = "io.sentry.animalsniffer"
2034
implementationClass = "io.sentry.gradle.SentryAnimalSnifferPlugin"
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: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
val file = distributionFile
57+
doLast {
58+
if (!file.exists()) {
59+
throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
60+
}
61+
if (file.length() == 0L) {
62+
throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
63+
}
64+
}
65+
}
66+
67+
extensions.configure<MavenPublishBaseExtension> { assignAarTypes() }
68+
69+
plugins.withId("java-library") {
70+
extensions.configure<MavenPublishBaseExtension> {
71+
// we have to disable javadoc publication in maven-publish plugin as it's not
72+
// including it in the .module file
73+
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861
74+
// and do it ourselves
75+
configure(JavaLibrary(JavadocJar.None(), sourcesJar = true))
76+
}
77+
78+
extensions.configure<JavaPluginExtension> { withJavadocJar() }
79+
}
80+
81+
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
82+
extensions.configure<PublishingExtension> {
83+
repositories.maven {
84+
name = "unityMaven"
85+
url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI()
86+
}
87+
}
88+
}

‎build.gradle.kts‎

Lines changed: 1 addition & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import com.vanniktech.maven.publish.JavaLibrary
2-
import com.vanniktech.maven.publish.JavadocJar
3-
import com.vanniktech.maven.publish.MavenPublishBaseExtension
4-
import groovy.util.Node
5-
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
61
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
72
import org.gradle.api.tasks.testing.logging.TestLogEvent
83

@@ -12,13 +7,12 @@ plugins {
127
alias(libs.plugins.detekt)
138
`maven-publish`
149
alias(libs.plugins.binary.compatibility.validator)
15-
alias(libs.plugins.vanniktech.maven.publish) apply false
1610
alias(libs.plugins.kotlin.android) apply false
1711
alias(libs.plugins.kotlin.multiplatform) apply false
1812
alias(libs.plugins.kotlin.jvm) apply false
1913
alias(libs.plugins.kotlin.spring) apply false
2014
alias(libs.plugins.buildconfig) apply false
21-
// dokka is required by gradle-maven-publish-plugin.
15+
// dokka is applied directly by sentry-compose; pinned here so it is on the classpath.
2216
alias(libs.plugins.dokka) apply false
2317
alias(libs.plugins.dokka.javadoc) apply false
2418
alias(libs.plugins.kotlin.compose) apply false
@@ -113,90 +107,6 @@ allprojects {
113107
}
114108
}
115109

116-
subprojects {
117-
apply { plugin("io.sentry.spotless") }
118-
apply { plugin("io.sentry.jdk-target") }
119-
120-
plugins.withId(Config.QualityPlugins.detektPlugin) {
121-
configure<DetektExtension> {
122-
buildUponDefaultConfig = true
123-
allRules = true
124-
config.setFrom("${rootProject.rootDir}/detekt.yml")
125-
baseline = file("detekt-baseline.xml")
126-
}
127-
}
128-
129-
if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support") {
130-
apply<DistributionPlugin>()
131-
apply<com.vanniktech.maven.publish.MavenPublishPlugin>()
132-
133-
val sep = File.separator
134-
135-
configure<DistributionContainer> {
136-
if (this@subprojects.name.contains("-compose")) {
137-
this.configureForMultiplatform(this@subprojects)
138-
} else {
139-
this.configureForJvm(this@subprojects)
140-
}
141-
// craft only uses zip archives
142-
this.forEach { dist ->
143-
if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) {
144-
tasks.named("distTar").configure { enabled = false }
145-
} else {
146-
tasks.named(dist.name + "DistTar").configure { enabled = false }
147-
}
148-
}
149-
}
150-
151-
tasks.named("distZip").configure {
152-
this.dependsOn("publishToMavenLocal")
153-
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
154-
this.doLast {
155-
if (!file.exists()) throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
156-
if (file.length() == 0L) throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
157-
}
158-
}
159-
160-
plugins.withId("java-library") {
161-
configure<MavenPublishBaseExtension> {
162-
// we have to disable javadoc publication in maven-publish plugin as it's not
163-
// including it in the .module file https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861
164-
// and do it ourselves
165-
configure(JavaLibrary(JavadocJar.None(), sourcesJar = true))
166-
}
167-
168-
configure<JavaPluginExtension> {
169-
withJavadocJar()
170-
}
171-
}
172-
173-
apply<MavenPublishPlugin>()
174-
175-
afterEvaluate {
176-
configure<MavenPublishBaseExtension> {
177-
assignAarTypes()
178-
}
179-
180-
// this is needed for sentry-unity to consume our artifacts locally as proper maven publication
181-
configure<PublishingExtension> {
182-
repositories {
183-
maven {
184-
name = "unityMaven"
185-
url = rootProject.layout.buildDirectory.file("unityMaven").get().asFile.toURI()
186-
}
187-
}
188-
}
189-
190-
// maven central info go to:
191-
// ~/.gradle/gradle.properties
192-
193-
// maven central info:
194-
// mavenCentralUsername=user name
195-
// mavenCentralPassword=password
196-
}
197-
}
198-
}
199-
200110
tasks.register("buildForCodeQL") {
201111
subprojects
202112
.filter {
@@ -217,53 +127,3 @@ tasks.register("buildForCodeQL") {
217127
}
218128
}
219129
}
220-
221-
/*
222-
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
223-
*
224-
* Copyright 2018 The Android Open Source Project
225-
*
226-
* Licensed under the Apache License, Version 2.0 (the "License");
227-
* you may not use this file except in compliance with the License.
228-
* You may obtain a copy of the License at
229-
*
230-
* http://www.apache.org/licenses/LICENSE-2.0
231-
*
232-
* Unless required by applicable law or agreed to in writing, software
233-
* distributed under the License is distributed on an "AS IS" BASIS,
234-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
235-
* See the License for the specific language governing permissions and
236-
* limitations under the License.
237-
*/
238-
239-
// Workaround for https://github.com/gradle/gradle/issues/3170
240-
fun MavenPublishBaseExtension.assignAarTypes() {
241-
pom {
242-
withXml {
243-
val dependencies = asNode().children().find {
244-
it is Node && it.name().toString().endsWith("dependencies")
245-
} as Node?
246-
247-
dependencies?.children()?.forEach { dep ->
248-
if (dep !is Node) {
249-
return@forEach
250-
}
251-
val group = dep.children().firstOrNull {
252-
it is Node && it.name().toString().endsWith("groupId")
253-
} as? Node
254-
val groupValue = group?.children()?.firstOrNull() as? String
255-
256-
val artifactId = dep.children().firstOrNull {
257-
it is Node && it.name().toString().endsWith("artifactId")
258-
} as? Node
259-
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String
260-
261-
if (artifactIdValue in Config.BuildScript.androidLibs) {
262-
dep.appendNode("type", "aar")
263-
} else if ("$groupValue:$artifactIdValue" in Config.BuildScript.androidXLibs) {
264-
dep.appendNode("type", "aar")
265-
}
266-
}
267-
}
268-
}
269-
}

0 commit comments

Comments
 (0)