Repository navigation
build: Apply convention plugins per module instead of the root subprojects block #6354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
markushi
wants to merge
6
commits into
main
Choose a base branch
from
refactor/apply-plugins-per-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+468
−185
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
514edd5
build: Apply convention plugins per module instead of the root subpro…
markushi f8f3432
Merge branch 'main' into refactor/apply-plugins-per-module [pr-shepherd]
sentry-junior[bot] cfd11d5
Merge branch 'main' into refactor/apply-plugins-per-module [pr-shepherd]
sentry-junior[bot] 8ba225a
[pr-shepherd] Merge origin/main into refactor/apply-plugins-per-module
sentry-junior[bot] 24d1c8d
[pr-shepherd] Merge origin/main into refactor/apply-plugins-per-module
sentry-junior[bot] 75163dd
Merge branch 'main' into refactor/apply-plugins-per-module [pr-shepherd]
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549 | ||
| * | ||
| * Copyright 2018 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
Check warning on line 17 in build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt
|
||
|
|
||
| package io.sentry.gradle | ||
|
|
||
| import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
| import groovy.util.Node | ||
|
|
||
| private val androidLibs = | ||
| setOf( | ||
| "sentry-android-core", | ||
| "sentry-android-ndk", | ||
| "sentry-android-fragment", | ||
| "sentry-android-navigation", | ||
| "sentry-android-navigation3", | ||
| "sentry-android-timber", | ||
| "sentry-compose-android", | ||
| "sentry-android-sqlite", | ||
| "sentry-android-replay", | ||
| ) | ||
|
|
||
| private val androidXLibs = listOf("androidx.core:core") | ||
|
|
||
| // Workaround for https://github.com/gradle/gradle/issues/3170 | ||
| fun MavenPublishBaseExtension.assignAarTypes() { | ||
| pom { | ||
| withXml { | ||
| val dependencies = | ||
| asNode().children().find { it is Node && it.name().toString().endsWith("dependencies") } | ||
| as Node? | ||
|
|
||
| dependencies?.children()?.forEach { dep -> | ||
| if (dep !is Node) { | ||
| return@forEach | ||
| } | ||
| val group = | ||
| dep.children().firstOrNull { it is Node && it.name().toString().endsWith("groupId") } | ||
| as? Node | ||
| val groupValue = group?.children()?.firstOrNull() as? String | ||
|
|
||
| val artifactId = | ||
| dep.children().firstOrNull { it is Node && it.name().toString().endsWith("artifactId") } | ||
| as? Node | ||
| val artifactIdValue = artifactId?.children()?.firstOrNull() as? String | ||
|
|
||
| if (artifactIdValue in androidLibs) { | ||
| dep.appendNode("type", "aar") | ||
| } else if ("$groupValue:$artifactIdValue" in androidXLibs) { | ||
| dep.appendNode("type", "aar") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
buildSrc/src/main/java/Publication.kt → ...in/kotlin/io/sentry/gradle/Publication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
build-logic/src/main/kotlin/io/sentry/gradle/SentryDetektPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package io.sentry.gradle | ||
|
|
||
| import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.kotlin.dsl.configure | ||
|
|
||
| /** Runs detekt on a module against the shared ruleset, with a per-module baseline. */ | ||
| class SentryDetektPlugin : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| project.pluginManager.apply("io.gitlab.arturbosch.detekt") | ||
|
|
||
| project.extensions.configure<DetektExtension> { | ||
| buildUponDefaultConfig = true | ||
| allRules = true | ||
| config.setFrom(project.isolated.rootProject.projectDirectory.file("detekt.yml")) | ||
| baseline = project.file("detekt-baseline.xml") | ||
| } | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
build-logic/src/main/kotlin/io/sentry/gradle/SentryPublishPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package io.sentry.gradle | ||
|
|
||
| import com.vanniktech.maven.publish.JavaLibrary | ||
| import com.vanniktech.maven.publish.JavadocJar | ||
| import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
| import java.io.File | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.distribution.DistributionContainer | ||
| import org.gradle.api.distribution.plugins.DistributionPlugin | ||
| import org.gradle.api.plugins.JavaPluginExtension | ||
| import org.gradle.api.publish.PublishingExtension | ||
| import org.gradle.kotlin.dsl.configure | ||
|
|
||
| /** Publishes a JVM or Android module and packages it as the zip distribution craft consumes. */ | ||
| class SentryPublishPlugin : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| project.configurePublishing(DistributionContainer::configureForJvm) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Publishes a Kotlin Multiplatform module. Separate from [SentryPublishPlugin] because the | ||
| * per-target distributions it lays out have no counterpart in a single-target module. | ||
| */ | ||
| class SentryMultiplatformPublishPlugin : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| project.configurePublishing(DistributionContainer::configureForMultiplatform) | ||
| } | ||
| } | ||
|
|
||
| private fun Project.configurePublishing( | ||
| configureDistributions: DistributionContainer.(Project) -> Unit | ||
| ) { | ||
| pluginManager.apply(DistributionPlugin::class.java) | ||
| pluginManager.apply("com.vanniktech.maven.publish") | ||
|
|
||
| extensions.configure<DistributionContainer> { | ||
| configureDistributions(project) | ||
| // craft only uses zip archives | ||
| forEach { dist -> | ||
| if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) { | ||
| tasks.named("distTar").configure { enabled = false } | ||
| } else { | ||
| tasks.named(dist.name + "DistTar").configure { enabled = false } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val sep = File.separator | ||
| val distributionFile = | ||
| layout.buildDirectory.file("distributions$sep$name-$version.zip").get().asFile | ||
|
|
||
| tasks.named("distZip").configure { | ||
| dependsOn("publishToMavenLocal") | ||
| val file = distributionFile | ||
| doLast { | ||
| if (!file.exists()) { | ||
| throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist") | ||
| } | ||
| if (file.length() == 0L) { | ||
| throw IllegalStateException("Distribution file: ${file.absolutePath} is empty") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extensions.configure<MavenPublishBaseExtension> { assignAarTypes() } | ||
|
|
||
| plugins.withId("java-library") { | ||
| extensions.configure<MavenPublishBaseExtension> { | ||
| // we have to disable javadoc publication in maven-publish plugin as it's not | ||
| // including it in the .module file | ||
| // https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861 | ||
| // and do it ourselves | ||
| configure(JavaLibrary(JavadocJar.None(), sourcesJar = true)) | ||
| } | ||
|
|
||
| extensions.configure<JavaPluginExtension> { withJavadocJar() } | ||
| } | ||
|
|
||
| // this is needed for sentry-unity to consume our artifacts locally as proper maven publication | ||
| extensions.configure<PublishingExtension> { | ||
| repositories.maven { | ||
| name = "unityMaven" | ||
| url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
| import com.vanniktech.maven.publish.JavaLibrary | ||
| import com.vanniktech.maven.publish.JavadocJar | ||
| import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
| import groovy.util.Node | ||
| import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
| import org.gradle.api.tasks.testing.logging.TestExceptionFormat | ||
| import org.gradle.api.tasks.testing.logging.TestLogEvent | ||
|
|
||
|
|
@@ -12,13 +7,12 @@ plugins { | |
| alias(libs.plugins.detekt) | ||
| `maven-publish` | ||
| alias(libs.plugins.binary.compatibility.validator) | ||
| alias(libs.plugins.vanniktech.maven.publish) apply false | ||
| alias(libs.plugins.kotlin.android) apply false | ||
| alias(libs.plugins.kotlin.multiplatform) apply false | ||
| alias(libs.plugins.kotlin.jvm) apply false | ||
| alias(libs.plugins.kotlin.spring) apply false | ||
| alias(libs.plugins.buildconfig) apply false | ||
| // dokka is required by gradle-maven-publish-plugin. | ||
| // dokka is applied directly by sentry-compose; pinned here so it is on the classpath. | ||
| alias(libs.plugins.dokka) apply false | ||
| alias(libs.plugins.dokka.javadoc) apply false | ||
| alias(libs.plugins.kotlin.compose) apply false | ||
|
|
@@ -113,90 +107,6 @@ allprojects { | |
| } | ||
| } | ||
|
|
||
| subprojects { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im crying right now because this is so beautiful |
||
| apply { plugin("io.sentry.spotless") } | ||
| apply { plugin("io.sentry.jdk-target") } | ||
|
|
||
| plugins.withId(Config.QualityPlugins.detektPlugin) { | ||
| configure<DetektExtension> { | ||
| buildUponDefaultConfig = true | ||
| allRules = true | ||
| config.setFrom("${rootProject.rootDir}/detekt.yml") | ||
| baseline = file("detekt-baseline.xml") | ||
| } | ||
| } | ||
|
|
||
| if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support") { | ||
| apply<DistributionPlugin>() | ||
| apply<com.vanniktech.maven.publish.MavenPublishPlugin>() | ||
|
|
||
| val sep = File.separator | ||
|
|
||
| configure<DistributionContainer> { | ||
| if (this@subprojects.name.contains("-compose")) { | ||
| this.configureForMultiplatform(this@subprojects) | ||
| } else { | ||
| this.configureForJvm(this@subprojects) | ||
| } | ||
| // craft only uses zip archives | ||
| this.forEach { dist -> | ||
| if (dist.name == DistributionPlugin.MAIN_DISTRIBUTION_NAME) { | ||
| tasks.named("distTar").configure { enabled = false } | ||
| } else { | ||
| tasks.named(dist.name + "DistTar").configure { enabled = false } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.named("distZip").configure { | ||
| this.dependsOn("publishToMavenLocal") | ||
| val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile | ||
| this.doLast { | ||
| if (!file.exists()) throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist") | ||
| if (file.length() == 0L) throw IllegalStateException("Distribution file: ${file.absolutePath} is empty") | ||
| } | ||
| } | ||
|
|
||
| plugins.withId("java-library") { | ||
| configure<MavenPublishBaseExtension> { | ||
| // we have to disable javadoc publication in maven-publish plugin as it's not | ||
| // including it in the .module file https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861 | ||
| // and do it ourselves | ||
| configure(JavaLibrary(JavadocJar.None(), sourcesJar = true)) | ||
| } | ||
|
|
||
| configure<JavaPluginExtension> { | ||
| withJavadocJar() | ||
| } | ||
| } | ||
|
|
||
| apply<MavenPublishPlugin>() | ||
|
|
||
| afterEvaluate { | ||
| configure<MavenPublishBaseExtension> { | ||
| assignAarTypes() | ||
| } | ||
|
|
||
| // this is needed for sentry-unity to consume our artifacts locally as proper maven publication | ||
| configure<PublishingExtension> { | ||
| repositories { | ||
| maven { | ||
| name = "unityMaven" | ||
| url = rootProject.layout.buildDirectory.file("unityMaven").get().asFile.toURI() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // maven central info go to: | ||
| // ~/.gradle/gradle.properties | ||
|
|
||
| // maven central info: | ||
| // mavenCentralUsername=user name | ||
| // mavenCentralPassword=password | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.register("buildForCodeQL") { | ||
| subprojects | ||
| .filter { | ||
|
|
@@ -217,53 +127,3 @@ tasks.register("buildForCodeQL") { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549 | ||
| * | ||
| * Copyright 2018 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // Workaround for https://github.com/gradle/gradle/issues/3170 | ||
| fun MavenPublishBaseExtension.assignAarTypes() { | ||
| pom { | ||
| withXml { | ||
| val dependencies = asNode().children().find { | ||
| it is Node && it.name().toString().endsWith("dependencies") | ||
| } as Node? | ||
|
|
||
| dependencies?.children()?.forEach { dep -> | ||
| if (dep !is Node) { | ||
| return@forEach | ||
| } | ||
| val group = dep.children().firstOrNull { | ||
| it is Node && it.name().toString().endsWith("groupId") | ||
| } as? Node | ||
| val groupValue = group?.children()?.firstOrNull() as? String | ||
|
|
||
| val artifactId = dep.children().firstOrNull { | ||
| it is Node && it.name().toString().endsWith("artifactId") | ||
| } as? Node | ||
| val artifactIdValue = artifactId?.children()?.firstOrNull() as? String | ||
|
|
||
| if (artifactIdValue in Config.BuildScript.androidLibs) { | ||
| dep.appendNode("type", "aar") | ||
| } else if ("$groupValue:$artifactIdValue" in Config.BuildScript.androidXLibs) { | ||
| dep.appendNode("type", "aar") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build-logic/src/main/kotlin/io/sentry/gradle/AarTypes.kt — This file is adapted from AndroidX MavenUploadHelper (Apache 2.0, Copyright 2018 The Android Open Source Project) and has a complete attribution header, but there is no matching entry in THIRD_PARTY_NOTICES.md. Add an entry with Source URL, License name, Copyright, Scope, and full license text.
Evidence
Identified by Warden · check-code-attribution · JAJ-FF6