Skip to content

Commit

Permalink
Use BuildIdentifier.getBuildPath() starting with Gradle 8.2
Browse files Browse the repository at this point in the history
Right now, 8.3 prints a deprecation warning for the getName() method:
https://scans.gradle.com/s/s23mexkai26qe/deprecations
  • Loading branch information
jjohannes authored and autonomousapps committed Sep 7, 2023
1 parent 518bc81 commit 32e2a9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/com/autonomousapps/internal/GradleVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import org.gradle.util.GradleVersion
internal object GradleVersions {
val current: GradleVersion = GradleVersion.current()
val gradle74: GradleVersion = GradleVersion.version("7.4")
val gradle82: GradleVersion = GradleVersion.version("8.2")
val isAtLeastGradle74: Boolean = current >= gradle74
val isAtLeastGradle82: Boolean = current >= gradle82
}
11 changes: 7 additions & 4 deletions src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.autonomousapps.Flags.projectPathRegex
import com.autonomousapps.Flags.shouldAnalyzeTests
import com.autonomousapps.getExtension
import com.autonomousapps.internal.*
import com.autonomousapps.internal.GradleVersions.isAtLeastGradle82
import com.autonomousapps.internal.advice.DslKind
import com.autonomousapps.internal.analyzer.*
import com.autonomousapps.internal.android.AgpVersion
Expand Down Expand Up @@ -836,10 +837,12 @@ internal class ProjectPlugin(private val project: Project) {
}

/** Get the buildPath of the current build from the root component of the resolution result. */
private fun Project.buildPath(configuration: String) = project.provider {
// Note: starting with Gradle 7.4, we can replace 'project.provider' with 'resolutionResult.rootComponent.map'
// FIXME use 'buildState.buildIdentifier.buildPath' with Gradle 8.2+
(configurations[configuration].incoming.resolutionResult.root.id as ProjectComponentIdentifier).build.name
private fun Project.buildPath(configuration: String) = configurations[configuration].incoming.resolutionResult.let {
if (isAtLeastGradle82) {
it.rootComponent.map { root -> (root.id as ProjectComponentIdentifier).build.buildPath }
} else {
project.provider { @Suppress("DEPRECATION") (it.root.id as ProjectComponentIdentifier).build.name }
}
}

private fun Project.isKaptApplied() = providers.provider { plugins.hasPlugin("kotlin-kapt") }
Expand Down

0 comments on commit 32e2a9f

Please sign in to comment.