Skip to content

Commit c495bae

Browse files
authored
Make version properties plugin more robust in a composite build (#90535)
The current logic in `VersionPropertiesPlugin` for determining the location of the "elasticsearch" project workspace doesn't account well for scenarios where the elasticsearch project itself is an included build in a larger composite. This change accounts for this by traversing the build hierarchy.
1 parent bd50658 commit c495bae

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesPlugin.java

+20-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import org.gradle.api.Plugin;
1212
import org.gradle.api.Project;
13+
import org.gradle.api.initialization.IncludedBuild;
14+
import org.gradle.api.invocation.Gradle;
1315
import org.gradle.api.provider.Provider;
1416

1517
import java.io.File;
@@ -18,13 +20,7 @@ public class VersionPropertiesPlugin implements Plugin<Project> {
1820

1921
@Override
2022
public void apply(Project project) {
21-
File workspaceDir;
22-
if (project.getGradle().getIncludedBuilds().isEmpty()) {
23-
// This is an included build, use the parent directory as workspace root
24-
workspaceDir = project.getRootDir().getParentFile();
25-
} else {
26-
workspaceDir = project.getRootDir();
27-
}
23+
File workspaceDir = locateElasticsearchWorkspace(project.getGradle());
2824

2925
// Register the service if not done yet
3026
File infoPath = new File(workspaceDir, "build-tools-internal");
@@ -34,4 +30,21 @@ public void apply(Project project) {
3430
});
3531
project.getExtensions().add("versions", serviceProvider.get().getProperties());
3632
}
33+
34+
private static File locateElasticsearchWorkspace(Gradle project) {
35+
if (project.getParent() == null) {
36+
// See if "elasticsearch" is one of the included builds, if so use that project directory
37+
for (IncludedBuild includedBuild : project.getIncludedBuilds()) {
38+
if (includedBuild.getName().equals("elasticsearch")) {
39+
return includedBuild.getProjectDir();
40+
}
41+
}
42+
43+
// Otherwise assume this project is the root elasticsearch workspace
44+
return project.getRootProject().getRootDir();
45+
} else {
46+
// We're an included build, so keep looking
47+
return locateElasticsearchWorkspace(project.getParent());
48+
}
49+
}
3750
}

0 commit comments

Comments
 (0)