Skip to content

Commit 38e2e1d

Browse files
authored
Detect and prevent configuration that triggers a Gradle bug (#31912)
* Detect and prevent configuration that triggers a Gradle bug As we found in #31862, this can lead to a lot of wasted time as it's not immediatly obvius what's going on. Givent how many projects we have it's getting increasingly easier to run into gradle/gradle#847.
1 parent aae0133 commit 38e2e1d

File tree

10 files changed

+27
-11
lines changed

10 files changed

+27
-11
lines changed

build.gradle

+16-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ subprojects {
222222
"org.elasticsearch.gradle:build-tools:${version}": ':build-tools',
223223
"org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
224224
"org.elasticsearch:elasticsearch:${version}": ':server',
225-
"org.elasticsearch:elasticsearch-cli:${version}": ':libs:cli',
225+
"org.elasticsearch:elasticsearch-cli:${version}": ':libs:elasticsearch-cli',
226226
"org.elasticsearch:elasticsearch-core:${version}": ':libs:core',
227227
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:nio',
228228
"org.elasticsearch:elasticsearch-x-content:${version}": ':libs:x-content',
@@ -622,6 +622,21 @@ gradle.projectsEvaluated {
622622
}
623623
}
624624
}
625+
// Having the same group and name for distinct projects causes Gradle to consider them equal when resolving
626+
// dependencies leading to hard to debug failures. Run a check across all project to prevent this from happening.
627+
// see: https://github.com/gradle/gradle/issues/847
628+
Map coordsToProject = [:]
629+
project.allprojects.forEach { p ->
630+
String coords = "${p.group}:${p.name}"
631+
if (false == coordsToProject.putIfAbsent(coords, p)) {
632+
throw new GradleException(
633+
"Detected that two projects: ${p.path} and ${coordsToProject[coords].path} " +
634+
"have the same name and group: ${coords}. " +
635+
"This doesn't currently work correctly in Gradle, see: " +
636+
"https://github.com/gradle/gradle/issues/847"
637+
)
638+
}
639+
}
625640
}
626641

627642
if (System.properties.get("build.compare") != null) {

client/test/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ apply plugin: 'elasticsearch.build'
2525
targetCompatibility = JavaVersion.VERSION_1_7
2626
sourceCompatibility = JavaVersion.VERSION_1_7
2727

28+
group = "${group}.client.test"
29+
2830
dependencies {
2931
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
3032
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"

libs/cli/build.gradle

-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ apply plugin: 'nebula.optional-base'
2424
apply plugin: 'nebula.maven-base-publish'
2525
apply plugin: 'nebula.maven-scm'
2626

27-
publishing {
28-
publications {
29-
nebula {
30-
artifactId 'elasticsearch-cli'
31-
}
32-
}
33-
}
34-
35-
archivesBaseName = 'elasticsearch-cli'
36-
3727
dependencies {
3828
compile 'net.sf.jopt-simple:jopt-simple:5.0.2'
3929
compile "org.elasticsearch:elasticsearch-core:${version}"

plugins/discovery-ec2/qa/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group = "${group}.plugins.discovery-ec2.qa"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group = "${group}.plugins.repository-azure.qa"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group = "${group}.plugins.repository-gcs.qa"

settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ if (extraProjects.exists()) {
131131

132132
// enable in preparation for Gradle 5.0
133133
enableFeaturePreview('STABLE_PUBLISHING')
134+
135+
project(":libs:cli").name = 'elasticsearch-cli'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group = "${group}.x-pack.qa.rolling-upgrade.with-system-key"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
group = "${group}.x-pack.qa.rolling-upgrade.without-system-key"

x-pack/qa/sql/security/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ dependencies {
44

55
Project mainProject = project
66

7+
group = "${group}.x-pack.qa.sql.security"
8+
79
subprojects {
810
// Use resources from the parent project in subprojects
911
sourceSets {

0 commit comments

Comments
 (0)