From 4f50612668d8c5914a8c7f591a2e09641d5eec3d Mon Sep 17 00:00:00 2001 From: Jesse Kershaw Date: Tue, 27 Jan 2026 13:25:21 +0100 Subject: [PATCH 1/2] Specify repository for node.js as exclusive by default By default, gradle checks all repositories in the order they are defined when resolving an artifact, unless a repository is declared that exclusively contains that artifact. In that case only that repository is checked when resolving the artifact. --- .../com/github/gradle/node/NodeExtension.kt | 6 ++++++ .../com/github/gradle/node/NodePlugin.kt | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt index 378a832d..d72f3a20 100644 --- a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt +++ b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt @@ -92,6 +92,12 @@ open class NodeExtension(project: Project) { */ val allowInsecureProtocol = project.objects.property() + /** + * Specifies whether the Node.js repository added to the project should be accessed exclusively. + * Only used if download is true + */ + val exclusiveRepository = project.objects.property().convention(true) + val npmCommand = project.objects.property().convention("npm") val npxCommand = project.objects.property().convention("npx") val pnpmCommand = project.objects.property().convention("pnpm") diff --git a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt index f2256696..bdb201f4 100644 --- a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt +++ b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt @@ -52,7 +52,8 @@ class NodePlugin : Plugin { addYarnRule(nodeExtension.enableTaskRules) project.afterEvaluate { if (nodeExtension.download.get()) { - nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull) } + nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull, + nodeExtension.exclusiveRepository.getOrElse(true)) } configureNodeSetupTask(nodeExtension) } } @@ -182,8 +183,8 @@ class NodePlugin : Plugin { } } - private fun addRepository(distUrl: String, allowInsecureProtocol: Boolean?) { - project.repositories.ivy { + private fun addRepository(distUrl: String, allowInsecureProtocol: Boolean?, exclusiveRepository: Boolean) { + val repository = project.repositories.ivy { name = "Node.js" setUrl(distUrl) patternLayout { @@ -197,6 +198,17 @@ class NodePlugin : Plugin { } allowInsecureProtocol?.let { isAllowInsecureProtocol = it } } + + if (exclusiveRepository) { + project.repositories.exclusiveContent { + forRepository { + repository + } + filter { + includeModule("org.nodejs", "node") + } + } + } } private fun configureNodeSetupTask(nodeExtension: NodeExtension) { From 19828b99fc0095b5bdac5e16b0a4e1dc712f2749 Mon Sep 17 00:00:00 2001 From: Jesse Kershaw Date: Fri, 30 Jan 2026 08:42:23 +0100 Subject: [PATCH 2/2] Remove config flag and always add the repository as exclusive If this causes compatibility issues, the distBaseUrl can be set to null and a repository can be manually specified --- .../com/github/gradle/node/NodeExtension.kt | 6 --- .../com/github/gradle/node/NodePlugin.kt | 40 ++++++++----------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt index d72f3a20..378a832d 100644 --- a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt +++ b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt @@ -92,12 +92,6 @@ open class NodeExtension(project: Project) { */ val allowInsecureProtocol = project.objects.property() - /** - * Specifies whether the Node.js repository added to the project should be accessed exclusively. - * Only used if download is true - */ - val exclusiveRepository = project.objects.property().convention(true) - val npmCommand = project.objects.property().convention("npm") val npxCommand = project.objects.property().convention("npx") val pnpmCommand = project.objects.property().convention("pnpm") diff --git a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt index bdb201f4..b29bb024 100644 --- a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt +++ b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt @@ -52,8 +52,7 @@ class NodePlugin : Plugin { addYarnRule(nodeExtension.enableTaskRules) project.afterEvaluate { if (nodeExtension.download.get()) { - nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull, - nodeExtension.exclusiveRepository.getOrElse(true)) } + nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull) } configureNodeSetupTask(nodeExtension) } } @@ -183,31 +182,24 @@ class NodePlugin : Plugin { } } - private fun addRepository(distUrl: String, allowInsecureProtocol: Boolean?, exclusiveRepository: Boolean) { - val repository = project.repositories.ivy { - name = "Node.js" - setUrl(distUrl) - patternLayout { - artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") - } - metadataSources { - artifact() + private fun addRepository(distUrl: String, allowInsecureProtocol: Boolean?) { + project.repositories.exclusiveContent { + forRepository { + project.repositories.ivy { + name = "Node.js" + setUrl(distUrl) + patternLayout { + artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") + } + metadataSources { + artifact() + } + allowInsecureProtocol?.let { isAllowInsecureProtocol = it } + } } - content { + filter { includeModule("org.nodejs", "node") } - allowInsecureProtocol?.let { isAllowInsecureProtocol = it } - } - - if (exclusiveRepository) { - project.repositories.exclusiveContent { - forRepository { - repository - } - filter { - includeModule("org.nodejs", "node") - } - } } }