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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 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] f78216a
chore: Merge origin/main into refactor/apply-plugins-per-module
markushi 5bf00d1
chore: Merge origin/main into refactor/apply-plugins-per-module
markushi eb05eb9
docs: Add AndroidX MavenUploadHelper to third-party notices
markushi 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
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. | ||
| */ | ||
|
|
||
| package io.sentry.gradle | ||
|
|
||
| import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
| import groovy.util.Node | ||
|
|
||
| private val androidLibs = | ||
|
markushi marked this conversation as resolved.
Resolved
|
||
| 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") | ||
|
markushi marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
| } | ||
94 changes: 94 additions & 0 deletions
94
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,94 @@ | ||
| 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") | ||
| dependsOn("publishAllPublicationsTo${DIST_MAVEN_REPO.replaceFirstChar { it.uppercase() }}Repository") | ||
| 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 | ||
|
markushi marked this conversation as resolved.
Resolved
|
||
| // https://github.com/vanniktech/gradle-maven-publish-plugin/issues/861 | ||
| // and do it ourselves | ||
| configure(JavaLibrary(JavadocJar.None(), sourcesJar = true)) | ||
| } | ||
|
|
||
| extensions.configure<JavaPluginExtension> { withJavadocJar() } | ||
| } | ||
|
|
||
| extensions.configure<PublishingExtension> { | ||
| // the dist zips craft publishes are assembled from this, see Publication.kt | ||
| repositories.maven { | ||
| name = DIST_MAVEN_REPO | ||
| url = distMavenDir.get().asFile.toURI() | ||
| } | ||
| // this is needed for sentry-unity to consume our artifacts locally as proper maven publication | ||
| repositories.maven { | ||
| name = "unityMaven" | ||
| url = isolated.rootProject.projectDirectory.dir("build${sep}unityMaven").asFile.toURI() | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.