Skip to content

Commit

Permalink
Fix config cache for build command
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Feb 11, 2025
1 parent a582fda commit 972ba25
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 39 deletions.
22 changes: 3 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ subprojects {

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 {
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
if (!file.exists()) throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
if (file.length() == 0L) throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
}
Expand Down Expand Up @@ -300,21 +300,6 @@ gradle.taskGraph.whenReady {
}
}

private val androidLibs = setOf(
"sentry-android-core",
"sentry-android-ndk",
"sentry-android-fragment",
"sentry-android-navigation",
"sentry-android-timber",
"sentry-compose-android",
"sentry-android-sqlite",
"sentry-android-replay"
)

private val androidXLibs = listOf(
"androidx.core:core"
)

/*
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
*
Expand All @@ -334,7 +319,6 @@ private val androidXLibs = listOf(
*/

// Workaround for https://github.com/gradle/gradle/issues/3170
@Suppress("UnstableApiUsage")
fun MavenPublishBaseExtension.assignAarTypes() {
pom {
withXml {
Expand All @@ -356,9 +340,9 @@ fun MavenPublishBaseExtension.assignAarTypes() {
} as? Node
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String

if (artifactIdValue in androidLibs) {
if (artifactIdValue in Config.BuildScript.androidLibs) {
dep.appendNode("type", "aar")
} else if ("$groupValue:$artifactIdValue" in androidXLibs) {
} else if ("$groupValue:$artifactIdValue" in Config.BuildScript.androidXLibs) {
dep.appendNode("type", "aar")
}
}
Expand Down
20 changes: 19 additions & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ object Config {
val grettyVersion = "4.0.0"
val gradleMavenPublishPlugin = "com.vanniktech.maven.publish"
val gradleMavenPublishPluginVersion = "0.30.0"
val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20"
val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:2.0.0"
val dokkaPluginAlias = "org.jetbrains.dokka"
val dokkaPluginJavadocAlias = "org.jetbrains.dokka-javadoc"
val composeGradlePlugin = "org.jetbrains.compose:compose-gradle-plugin:$composeVersion"
val commonsCompressOverride = "org.apache.commons:commons-compress:1.25.0"
}
Expand Down Expand Up @@ -271,4 +272,21 @@ object Config {
val errorprone = "com.google.errorprone:error_prone_core:2.11.0"
val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.5"
}

object BuildScript {
val androidLibs = setOf(
"sentry-android-core",
"sentry-android-ndk",
"sentry-android-fragment",
"sentry-android-navigation",
"sentry-android-timber",
"sentry-compose-android",
"sentry-android-sqlite",
"sentry-android-replay"
)

val androidXLibs = listOf(
"androidx.core:core"
)
}
}
16 changes: 9 additions & 7 deletions buildSrc/src/main/java/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ private object Consts {
fun DistributionContainer.configureForMultiplatform(project: Project) {
val sep = File.separator
val version = project.properties["versionName"].toString()
val name = project.name

this.maybeCreate("android").contents {
from("build${sep}publications${sep}androidRelease") {
renameModule(project.name, "android", version = version)
renameModule(name, "android", version = version)
}
from("build${sep}outputs${sep}aar") {
include("*-release*")
Expand All @@ -32,7 +33,7 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
}
this.getByName("main").contents {
from("build${sep}publications${sep}kotlinMultiplatform") {
renameModule(project.name, version = version)
renameModule(name, version = version)
}
from("build${sep}kotlinToolingMetadata")
from("build${sep}libs") {
Expand All @@ -48,7 +49,7 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
this.maybeCreate("desktop").contents {
// kotlin multiplatform modules
from("build${sep}publications${sep}desktop") {
renameModule(project.name, "desktop", version = version)
renameModule(name, "desktop", version = version)
}
from("build${sep}libs") {
include("*desktop*")
Expand All @@ -69,27 +70,28 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
fun DistributionContainer.configureForJvm(project: Project) {
val sep = File.separator
val version = project.properties["versionName"].toString()
val name = project.name

this.getByName("main").contents {
// non android modules
from("build${sep}libs")
from("build${sep}publications${sep}maven") {
renameModule(project.name, version = version)
renameModule(name, version = version)
}
// android modules
from("build${sep}outputs${sep}aar") {
include("*-release*")
}
from("build${sep}publications${sep}release") {
renameModule(project.name, version = version)
renameModule(name, version = version)
}
from("build${sep}intermediates${sep}java_doc_jar${sep}release") {
include("*javadoc*")
rename { it.replace("release", "${project.name}-$version") }
rename { it.replace("release", "$name-$version") }
}
from("build${sep}intermediates${sep}source_jar${sep}release") {
include("*sources*")
rename { it.replace("release", "${project.name}-$version") }
rename { it.replace("release", "$name-$version") }
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.configuration-cache=true

org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

# Daemons workers
org.gradle.workers.max=2

Expand Down
4 changes: 3 additions & 1 deletion sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-fragment/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-replay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
4 changes: 3 additions & 1 deletion sentry-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
5 changes: 4 additions & 1 deletion sentry-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
id(Config.BuildPlugins.dokkaPluginAlias)
id(Config.BuildPlugins.dokkaPluginJavadocAlias)
`maven-publish` // necessary for publishMavenLocal task to publish correct artifacts
}

Expand Down Expand Up @@ -81,7 +82,9 @@ android {
}

buildTypes {
getByName("debug")
getByName("debug") {
consumerProguardFiles("proguard-rules.pro")
}
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
`java-library`
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.gradleup.shadow") version "9.0.0-beta8"
}

fun relocatePackages(shadowJar: ShadowJar) {
Expand Down Expand Up @@ -89,7 +89,7 @@ tasks {
// building the final javaagent jar is done in 3 steps:

// 1. all distro specific javaagent libs are relocated
create("relocateJavaagentLibs", ShadowJar::class.java) {
register("relocateJavaagentLibs", ShadowJar::class.java) {
configurations = listOf(javaagentLibs)

duplicatesStrategy = DuplicatesStrategy.FAIL
Expand All @@ -114,7 +114,7 @@ tasks {
// having a separate task for isolating javaagent libs is required to avoid duplicates with the upstream javaagent
// duplicatesStrategy in shadowJar won't be applied when adding files with with(CopySpec) because each CopySpec has
// its own duplicatesStrategy
create("isolateJavaagentLibs", Copy::class.java) {
register("isolateJavaagentLibs", Copy::class.java) {
dependsOn(findByName("relocateJavaagentLibs"))
with(isolateClasses(findByName("relocateJavaagentLibs")!!.outputs.files))

Expand Down

0 comments on commit 972ba25

Please sign in to comment.