Skip to content

Commit fee7f67

Browse files
authored
Add allowDuplicateProjectNames (#239)
* Add NmcpAggregationExtension.allowDuplicateProjectNames * better error message
1 parent ed8ac62 commit fee7f67

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
org.gradle.jvmargs=-Xmx2g
2+
3+
org.gradle.configuration-cache.parallel=true
4+
org.gradle.unsafe.isolated-projects=true
5+
org.gradle.configuration-cache=true
6+
ksp.project.isolation.enabled=true

nmcp/api/nmcp.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class nmcp/LocalRepositoryOptions {
1919
public abstract interface class nmcp/NmcpAggregationExtension {
2020
public abstract fun centralPortal (Lorg/gradle/api/Action;)V
2121
public abstract fun getAllFiles ()Lorg/gradle/api/file/FileCollection;
22+
public abstract fun getAllowDuplicateProjectNames ()Lorg/gradle/api/provider/Property;
2223
public abstract fun getAllowEmptyAggregation ()Lorg/gradle/api/provider/Property;
2324
public abstract fun localRepository (Lorg/gradle/api/Action;)V
2425
public abstract fun publishAllProjectsProbablyBreakingProjectIsolation ()V

nmcp/src/main/kotlin/nmcp/NmcpAggregationExtension.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ interface NmcpAggregationExtension {
4444
* Set this to true to allow empty aggregations.
4545
*/
4646
val allowEmptyAggregation: Property<Boolean>
47+
48+
/**
49+
* By default, Nmcp errors if there are duplicate project names because
50+
* it confuses the dependency resolution algorithm.
51+
*
52+
* If you have duplicate project names that do not contribute publishing,
53+
* set this to true to allow them.
54+
*
55+
* See https://github.com/gradle/gradle/issues/36167 for more details.
56+
*/
57+
val allowDuplicateProjectNames: Property<Boolean>
4758
}

nmcp/src/main/kotlin/nmcp/internal/DefaultNmcpAggregationExtension.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
5252

5353
project.afterEvaluate {
5454
val allNames = mutableSetOf<String>()
55-
project.allprojects {
56-
check (!allNames.contains(it.name.lowercase())) {
57-
"Nmcp: duplicate project name: '${it.name}'. This is usually resolved by setting your root project name in your settings.gradle[.kts] file: `rootProject.name = \"\${someUniqueName}\". " +
58-
"See https://github.com/gradle/gradle/issues/36167 for more details"
55+
if(!allowDuplicateProjectNames.orElse(false).get()) {
56+
project.allprojects {
57+
check(!allNames.contains(it.name.lowercase())) {
58+
"""
59+
Nmcp: some projects have the same name: '${'$'}{it.name}'. This creates issues when resolving the aggregation.
60+
You can usually resolve this error by renaming your projects (including possibly your root project).
61+
Or you can disable this check by calling `allowDuplicateProjectNames.set(true)`.
62+
See https://github.com/gradle/gradle/issues/36167 for more details.
63+
""".trimIndent()
64+
}
65+
allNames.add(it.name.lowercase())
5966
}
60-
allNames.add(it.name.lowercase())
6167
}
6268

6369
if (!allowEmptyAggregation.orElse(false).get()) {
@@ -99,6 +105,8 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
99105
}
100106

101107
abstract override val allowEmptyAggregation: Property<Boolean>
108+
109+
abstract override val allowDuplicateProjectNames: Property<Boolean>
102110
}
103111

104112
private fun isCompatible(artifactResult: ArtifactResult): Boolean {

nmcp/src/test/kotlin/MainTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MainTest {
1818
.withArguments("nmcpZipAggregation")
1919
.buildAndFail()
2020

21-
assert(result.output.contains("duplicate project name"))
21+
assert(result.output.contains("some projects have the same name"))
2222
}
2323

2424
@Test

0 commit comments

Comments
 (0)