From 47f73b4224d8827f2d00ffc620fcc2625055fe88 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 15 Oct 2024 15:39:48 +0200 Subject: [PATCH] fix(gradle-plugin): Guard `dependencyResolutionManagement` usage Do not use that feature before it was added in Gradle 6.8, see [1]. This is a fixup for 8deb4b3. Fixes #9282. [1]: https://docs.gradle.org/6.8/release-notes.html#central-declaration-of-repositories Signed-off-by: Sebastian Schuberth --- .../gradle-plugin/src/main/kotlin/OrtModelBuilder.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/package-managers/gradle-plugin/src/main/kotlin/OrtModelBuilder.kt b/plugins/package-managers/gradle-plugin/src/main/kotlin/OrtModelBuilder.kt index c8765b570c2a0..653c674b98b60 100644 --- a/plugins/package-managers/gradle-plugin/src/main/kotlin/OrtModelBuilder.kt +++ b/plugins/package-managers/gradle-plugin/src/main/kotlin/OrtModelBuilder.kt @@ -58,11 +58,14 @@ internal class OrtModelBuilder : ToolingModelBuilder { override fun canBuild(modelName: String): Boolean = modelName == OrtDependencyTreeModel::class.java.name override fun buildAll(modelName: String, project: Project): OrtDependencyTreeModel { - // There currently is no way to access Gradle settings without using internal API, see - // https://github.com/gradle/gradle/issues/18616. - val settings = (project.gradle as GradleInternal).settings + if (GradleVersion.current() >= GradleVersion.version("6.8")) { + // There currently is no way to access Gradle settings without using internal API, see + // https://github.com/gradle/gradle/issues/18616. + val settings = (project.gradle as GradleInternal).settings + + settings.dependencyResolutionManagement.repositories.associateNamesWithUrlsTo(repositories) + } - settings.dependencyResolutionManagement.repositories.associateNamesWithUrlsTo(repositories) project.repositories.associateNamesWithUrlsTo(repositories) val relevantConfigurations = project.configurations.filter { it.isRelevant() }