Skip to content

Commit

Permalink
chore: use non-deprecated method when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Jan 9, 2025
1 parent c9b15ef commit 309cd95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/com/autonomousapps/internal/GradleVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal object GradleVersions {
private val gradle83: GradleVersion = GradleVersion.version("8.3")
private val gradle85: GradleVersion = GradleVersion.version("8.5")
private val gradle88: GradleVersion = GradleVersion.version("8.8")
private val gradle811: GradleVersion = GradleVersion.version("8.11")

/** Minimum supported version of Gradle. */
@JvmField val minGradleVersion: GradleVersion = gradle74
Expand All @@ -24,6 +25,9 @@ internal object GradleVersions {
val isAtLeastGradle83: Boolean = current >= gradle83
val isAtLeastGradle85: Boolean = current >= gradle85

/** Minimum version of Gradle for [org.gradle.api.artifacts.ProjectDependency.getPath] */
val isAtLeastGradle811: Boolean = current >= gradle811

/**
* Minimum version of Gradle for [BuildHealthPlugin][com.autonomousapps.BuildHealthPlugin], because it uses the new
* lifecycle callbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ internal fun Dependency.toCoordinates(): Coordinates? {
*/
internal fun Dependency.toIdentifier(): Pair<ModuleInfo, GradleVariantIdentification>? = when (this) {
is ProjectDependency -> {
val identifier = dependencyProject.path
val identifier = if (GradleVersions.isAtLeastGradle811) {
path
} else {
@Suppress("DEPRECATION")
dependencyProject.path
}
Pair(ModuleInfo(identifier.intern()), targetGradleVariantIdentification())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test
import org.gradle.util.GradleVersion
import java.io.File

/**
Expand Down Expand Up @@ -208,8 +209,17 @@ public abstract class GradleTestKitSupportExtension(private val project: Project
return configurations.findByName(classpath)?.allDependencies
?.filterIsInstance<ProjectDependency>()
// filter out self-dependency
?.filterNot { it.dependencyProject == project }
?.map { "${it.dependencyProject.path}:$taskName" }
?.filterNot { projectPath(it) == project.path }
?.map { "${projectPath(it)}:$taskName" }
}

private val isAtLeastGradle811 = GradleVersion.current() >= GradleVersion.version("8.11")

private fun projectPath(projectDependency: ProjectDependency): String = if (isAtLeastGradle811) {
projectDependency.path
} else {
@Suppress("DEPRECATION")
projectDependency.dependencyProject.path
}

/**
Expand Down

0 comments on commit 309cd95

Please sign in to comment.