Browse Source

Fix configuration cache compatibility issues in gradle plugins (#87567)

This fixes references to project that makes the plugin incompatible with Gradle
configuration cache. We also remove custom xpackProject utility:

using xpackProject in certain situations can break configure configuration cache compatibility as it uses a mutual project object under the hood that is discouraged to use in some use cases (e.g. at execution time)

It always breaks compatibility with --configure-on-demand

using xpackProject uses the project of the :x-pack project. referencing other project objects from other subproject should avoided where possible to decouple (sub project configurations). There's a good explanation of why we want to decouple our project configurations as much as possible here: https://docs.gradle.org/current/userguide/multi_project_configuration_and_execution.html#sec:decoupled_projects

it adds little value over default out of the box gradle api (just use project(':x-pack:someProject') instead of xpackProject('someProject') Also in some occasions its even shorter. e.g. when this is used as xpackProject('someProject').path instead of just passing :x-pack:someProject

I'll try to put a bit more context in the PR description in the future to make the motivation behind these kind of changes more clear upfront

Related to #57918
Rene Groeschke 3 years ago
parent
commit
95d56cc262
43 changed files with 144 additions and 109 deletions
  1. 15 2
      build-tools-internal/src/main/groovy/org/elasticsearch/gradle/internal/doc/DocsTestPlugin.groovy
  2. 4 4
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BaseInternalPluginBuildPlugin.java
  3. 44 35
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalBwcGitPlugin.java
  4. 33 18
      build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/YamlRestCompatTestPlugin.java
  5. 1 3
      x-pack/build.gradle
  6. 4 4
      x-pack/docs/build.gradle
  7. 1 1
      x-pack/plugin/async-search/build.gradle
  8. 1 1
      x-pack/plugin/autoscaling/build.gradle
  9. 1 1
      x-pack/plugin/ccr/build.gradle
  10. 1 1
      x-pack/plugin/deprecation/build.gradle
  11. 1 1
      x-pack/plugin/enrich/build.gradle
  12. 1 1
      x-pack/plugin/eql/build.gradle
  13. 1 1
      x-pack/plugin/graph/build.gradle
  14. 1 1
      x-pack/plugin/identity-provider/build.gradle
  15. 1 1
      x-pack/plugin/ilm/build.gradle
  16. 1 1
      x-pack/plugin/ml/build.gradle
  17. 1 1
      x-pack/plugin/ml/qa/ml-with-security/build.gradle
  18. 1 1
      x-pack/plugin/old-lucene-versions/build.gradle
  19. 1 1
      x-pack/plugin/repositories-metering-api/build.gradle
  20. 1 1
      x-pack/plugin/rollup/build.gradle
  21. 1 1
      x-pack/plugin/searchable-snapshots/build.gradle
  22. 1 1
      x-pack/plugin/security/build.gradle
  23. 1 1
      x-pack/plugin/shutdown/build.gradle
  24. 1 1
      x-pack/plugin/snapshot-based-recoveries/build.gradle
  25. 1 1
      x-pack/plugin/snapshot-repo-test-kit/build.gradle
  26. 1 1
      x-pack/plugin/sql/build.gradle
  27. 1 1
      x-pack/plugin/sql/jdbc/build.gradle
  28. 2 2
      x-pack/plugin/sql/qa/jdbc/build.gradle
  29. 1 1
      x-pack/plugin/sql/qa/jdbc/security/build.gradle
  30. 3 3
      x-pack/plugin/sql/qa/server/build.gradle
  31. 1 1
      x-pack/plugin/sql/qa/server/security/build.gradle
  32. 3 3
      x-pack/plugin/sql/sql-action/build.gradle
  33. 1 1
      x-pack/plugin/sql/sql-cli/build.gradle
  34. 1 1
      x-pack/plugin/sql/sql-client/build.gradle
  35. 1 1
      x-pack/plugin/stack/build.gradle
  36. 1 1
      x-pack/plugin/text-structure/build.gradle
  37. 1 1
      x-pack/plugin/text-structure/qa/text-structure-with-security/build.gradle
  38. 1 1
      x-pack/plugin/transform/build.gradle
  39. 1 1
      x-pack/plugin/watcher/build.gradle
  40. 1 1
      x-pack/qa/openldap-tests/build.gradle
  41. 1 1
      x-pack/qa/runtime-fields/build.gradle
  42. 1 1
      x-pack/qa/saml-idp-tests/build.gradle
  43. 2 2
      x-pack/qa/xpack-prefix-rest-compat/build.gradle

+ 15 - 2
build-tools-internal/src/main/groovy/org/elasticsearch/gradle/internal/doc/DocsTestPlugin.groovy

@@ -15,14 +15,27 @@ import org.elasticsearch.gradle.internal.test.rest.CopyRestTestsTask
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.file.Directory
+import org.gradle.api.file.ProjectLayout
+import org.gradle.api.internal.file.FileOperations
 import org.gradle.api.provider.Provider
 import org.gradle.api.tasks.TaskProvider
 
+import javax.inject.Inject
+
 /**
  * Sets up tests for documentation.
  */
 class DocsTestPlugin implements Plugin<Project> {
 
+    private FileOperations fileOperations
+    private ProjectLayout projectLayout
+
+    @Inject
+    DocsTestPlugin(FileOperations fileOperations, ProjectLayout projectLayout) {
+        this.projectLayout = projectLayout
+        this.fileOperations = fileOperations
+    }
+
     @Override
     void apply(Project project) {
         project.pluginManager.apply('elasticsearch.internal-yaml-rest-test')
@@ -62,12 +75,12 @@ class DocsTestPlugin implements Plugin<Project> {
             }
         }
 
-        Provider<Directory> restRootDir = project.getLayout().buildDirectory.dir("rest")
+        Provider<Directory> restRootDir = projectLayout.buildDirectory.dir("rest")
         TaskProvider<RestTestsFromSnippetsTask> buildRestTests = project.tasks.register('buildRestTests', RestTestsFromSnippetsTask) {
             defaultSubstitutions = commonDefaultSubstitutions
             testRoot.convention(restRootDir)
             doFirst {
-                project.delete(restRootDir)
+                fileOperations.delete(restRootDir)
             }
         }
 

+ 4 - 4
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BaseInternalPluginBuildPlugin.java

@@ -46,9 +46,9 @@ public class BaseInternalPluginBuildPlugin implements Plugin<Project> {
         // We might want to port this into a general pattern later on.
         project.getExtensions()
             .getExtraProperties()
-            .set("addQaCheckDependencies", new Closure<Object>(BaseInternalPluginBuildPlugin.this, BaseInternalPluginBuildPlugin.this) {
-                public void doCall(Object it) {
-                    project.afterEvaluate(project1 -> {
+            .set("addQaCheckDependencies", new Closure<Project>(BaseInternalPluginBuildPlugin.this, BaseInternalPluginBuildPlugin.this) {
+                public void doCall(Project proj) {
+                    proj.afterEvaluate(project1 -> {
                         // let check depend on check tasks of qa sub-projects
                         final var checkTaskProvider = project1.getTasks().named("check");
                         Optional<Project> qaSubproject = project1.getSubprojects()
@@ -63,7 +63,7 @@ public class BaseInternalPluginBuildPlugin implements Plugin<Project> {
                 }
 
                 public void doCall() {
-                    doCall(null);
+                    doCall();
                 }
             });
 

+ 44 - 35
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalBwcGitPlugin.java

@@ -15,12 +15,14 @@ import org.gradle.api.GradleException;
 import org.gradle.api.Plugin;
 import org.gradle.api.Project;
 import org.gradle.api.Task;
+import org.gradle.api.file.ProjectLayout;
 import org.gradle.api.logging.Logger;
 import org.gradle.api.plugins.ExtraPropertiesExtension;
 import org.gradle.api.provider.Provider;
 import org.gradle.api.provider.ProviderFactory;
 import org.gradle.api.tasks.TaskContainer;
 import org.gradle.api.tasks.TaskProvider;
+import org.gradle.initialization.layout.BuildLayout;
 import org.gradle.process.ExecOperations;
 import org.gradle.process.ExecResult;
 import org.gradle.process.ExecSpec;
@@ -39,47 +41,51 @@ import static java.util.Arrays.asList;
 
 public class InternalBwcGitPlugin implements Plugin<Project> {
 
-    private final ProviderFactory providerFactory;
+    private final BuildLayout buildLayout;
     private final ExecOperations execOperations;
+    private final ProjectLayout projectLayout;
+    private final ProviderFactory providerFactory;
 
     private BwcGitExtension gitExtension;
-    private Project project;
 
     @Inject
-    public InternalBwcGitPlugin(ProviderFactory providerFactory, ExecOperations execOperations) {
-        this.providerFactory = providerFactory;
+    public InternalBwcGitPlugin(
+        BuildLayout buildLayout,
+        ExecOperations execOperations,
+        ProjectLayout projectLayout,
+        ProviderFactory providerFactory
+    ) {
+        this.buildLayout = buildLayout;
         this.execOperations = execOperations;
+        this.projectLayout = projectLayout;
+        this.providerFactory = providerFactory;
     }
 
     @Override
     public void apply(Project project) {
-        this.project = project;
         this.gitExtension = project.getExtensions().create("bwcGitConfig", BwcGitExtension.class);
-        Provider<String> remote = providerFactory.systemProperty("bwc.remote").forUseAtConfigurationTime().orElse("elastic");
+        Provider<String> remote = providerFactory.systemProperty("bwc.remote").orElse("elastic");
 
         TaskContainer tasks = project.getTasks();
         TaskProvider<LoggedExec> createCloneTaskProvider = tasks.register("createClone", LoggedExec.class, createClone -> {
             createClone.onlyIf(task -> this.gitExtension.getCheckoutDir().get().exists() == false);
-            createClone.setCommandLine(asList("git", "clone", project.getRootDir(), gitExtension.getCheckoutDir().get()));
+            createClone.setCommandLine(asList("git", "clone", buildLayout.getRootDirectory(), gitExtension.getCheckoutDir().get()));
         });
 
+        ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
         TaskProvider<LoggedExec> findRemoteTaskProvider = tasks.register("findRemote", LoggedExec.class, findRemote -> {
             findRemote.dependsOn(createCloneTaskProvider);
             // TODO Gradle should provide property based configuration here
             findRemote.setWorkingDir(gitExtension.getCheckoutDir().get());
-
             findRemote.setCommandLine(asList("git", "remote", "-v"));
             ByteArrayOutputStream output = new ByteArrayOutputStream();
             findRemote.setStandardOutput(output);
-            findRemote.doLast(t -> {
-                ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
-                extraProperties.set("remoteExists", isRemoteAvailable(remote, output));
-            });
+            findRemote.doLast(t -> { extraProperties.set("remoteExists", isRemoteAvailable(remote, output)); });
         });
 
         TaskProvider<LoggedExec> addRemoteTaskProvider = tasks.register("addRemote", LoggedExec.class, addRemote -> {
             addRemote.dependsOn(findRemoteTaskProvider);
-            addRemote.onlyIf(task -> ((boolean) project.getExtensions().getExtraProperties().get("remoteExists")) == false);
+            addRemote.onlyIf(task -> ((boolean) extraProperties.get("remoteExists")) == false);
             addRemote.setWorkingDir(gitExtension.getCheckoutDir().get());
             String remoteRepo = remote.get();
             // for testing only we can override the base remote url
@@ -88,8 +94,9 @@ public class InternalBwcGitPlugin implements Plugin<Project> {
             addRemote.setCommandLine(asList("git", "remote", "add", remoteRepo, remoteRepoUrl));
         });
 
+        boolean isOffline = project.getGradle().getStartParameter().isOffline();
         TaskProvider<LoggedExec> fetchLatestTaskProvider = tasks.register("fetchLatest", LoggedExec.class, fetchLatest -> {
-            var gitFetchLatest = project.getProviders().systemProperty("tests.bwc.git_fetch_latest").orElse("true").map(fetchProp -> {
+            var gitFetchLatest = providerFactory.systemProperty("tests.bwc.git_fetch_latest").orElse("true").map(fetchProp -> {
                 if ("true".equals(fetchProp)) {
                     return true;
                 }
@@ -98,33 +105,35 @@ public class InternalBwcGitPlugin implements Plugin<Project> {
                 }
                 throw new GradleException("tests.bwc.git_fetch_latest must be [true] or [false] but was [" + fetchProp + "]");
             });
-            fetchLatest.onlyIf(t -> project.getGradle().getStartParameter().isOffline() == false && gitFetchLatest.get());
+            fetchLatest.onlyIf(t -> isOffline == false && gitFetchLatest.get());
             fetchLatest.dependsOn(addRemoteTaskProvider);
             fetchLatest.setWorkingDir(gitExtension.getCheckoutDir().get());
             fetchLatest.setCommandLine(asList("git", "fetch", "--all"));
         });
 
+        String projectPath = project.getPath();
         TaskProvider<Task> checkoutBwcBranchTaskProvider = tasks.register("checkoutBwcBranch", checkoutBwcBranch -> {
             checkoutBwcBranch.dependsOn(fetchLatestTaskProvider);
-            checkoutBwcBranch.doLast(t -> {
-                File checkoutDir = gitExtension.getCheckoutDir().get();
-                Logger logger = project.getLogger();
-                String bwcBranch = this.gitExtension.getBwcBranch().get();
-                final String refspec = providerFactory.systemProperty("bwc.refspec." + bwcBranch)
-                    .orElse(providerFactory.systemProperty("tests.bwc.refspec." + bwcBranch))
-                    .getOrElse(remote.get() + "/" + bwcBranch);
-
-                String effectiveRefSpec = maybeAlignedRefSpec(logger, refspec);
-
-                logger.lifecycle("Performing checkout of {}...", refspec);
-                LoggedExec.exec(execOperations, spec -> {
-                    spec.workingDir(checkoutDir);
-                    spec.commandLine("git", "checkout", effectiveRefSpec);
-                });
-
-                String checkoutHash = GitInfo.gitInfo(checkoutDir).getRevision();
-                logger.lifecycle("Checkout hash for {} is {}", project.getPath(), checkoutHash);
-                writeFile(new File(project.getBuildDir(), "refspec"), checkoutHash);
+            checkoutBwcBranch.doLast(new Action<Task>() {
+                @Override
+                public void execute(Task task) {
+                    File checkoutDir = gitExtension.getCheckoutDir().get();
+                    String bwcBranch = gitExtension.getBwcBranch().get();
+                    final String refspec = providerFactory.systemProperty("bwc.refspec." + bwcBranch)
+                        .orElse(providerFactory.systemProperty("tests.bwc.refspec." + bwcBranch))
+                        .getOrElse(remote.get() + "/" + bwcBranch);
+
+                    String effectiveRefSpec = maybeAlignedRefSpec(task.getLogger(), refspec);
+                    task.getLogger().lifecycle("Performing checkout of {}...", refspec);
+                    LoggedExec.exec(execOperations, spec -> {
+                        spec.workingDir(checkoutDir);
+                        spec.commandLine("git", "checkout", effectiveRefSpec);
+                    });
+
+                    String checkoutHash = GitInfo.gitInfo(checkoutDir).getRevision();
+                    task.getLogger().lifecycle("Checkout hash for {} is {}", projectPath, checkoutHash);
+                    writeFile(projectLayout.getBuildDirectory().file("refspec").get().getAsFile(), checkoutHash);
+                }
             });
         });
 
@@ -166,7 +175,7 @@ public class InternalBwcGitPlugin implements Plugin<Project> {
 
         String timeOfCurrent = execInCheckoutDir(execSpec -> {
             execSpec.commandLine(asList("git", "show", "--no-patch", "--no-notes", "--pretty='%cD'"));
-            execSpec.workingDir(project.getRootDir());
+            execSpec.workingDir(buildLayout.getRootDirectory());
         });
 
         logger.lifecycle("Commit date of current: {}", timeOfCurrent);

+ 33 - 18
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/YamlRestCompatTestPlugin.java

@@ -27,7 +27,10 @@ import org.gradle.api.Task;
 import org.gradle.api.artifacts.Configuration;
 import org.gradle.api.artifacts.Dependency;
 import org.gradle.api.file.Directory;
+import org.gradle.api.file.ProjectLayout;
 import org.gradle.api.file.RelativePath;
+import org.gradle.api.internal.file.FileOperations;
+import org.gradle.api.plugins.ExtraPropertiesExtension;
 import org.gradle.api.plugins.JavaBasePlugin;
 import org.gradle.api.provider.Provider;
 import org.gradle.api.tasks.SourceSet;
@@ -40,6 +43,8 @@ import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.Map;
 
+import javax.inject.Inject;
+
 import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupYamlRestTestDependenciesDefaults;
 
 /**
@@ -57,6 +62,14 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
     private static final Path RELATIVE_REST_PROJECT_RESOURCES = Path.of("src/yamlRestTest/resources");
     private static final int COMPATIBLE_VERSION = Version.fromString(VersionProperties.getVersions().get("elasticsearch")).getMajor() - 1;
     private static final String SOURCE_SET_NAME = "yamlRestTestV" + COMPATIBLE_VERSION + "Compat";
+    private ProjectLayout projectLayout;
+    private FileOperations fileOperations;
+
+    @Inject
+    public YamlRestCompatTestPlugin(ProjectLayout projectLayout, FileOperations fileOperations) {
+        this.projectLayout = projectLayout;
+        this.fileOperations = fileOperations;
+    }
 
     @Override
     public void apply(Project project) {
@@ -85,13 +98,15 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
             .project(Map.of("path", ":distribution:bwc:maintenance", "configuration", "checkout"));
         project.getDependencies().add(bwcMinorConfig.getName(), bwcMinor);
 
+        String projectPath = project.getPath();
+        ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
         Provider<CopyRestApiTask> copyCompatYamlSpecTask = project.getTasks()
             .register("copyRestCompatApiTask", CopyRestApiTask.class, task -> {
                 task.dependsOn(bwcMinorConfig);
                 task.setConfig(bwcMinorConfig);
                 task.setAdditionalConfig(bwcMinorConfig);
                 task.getInclude().set(extension.getRestApi().getInclude());
-                task.getOutputResourceDir().set(project.getLayout().getBuildDirectory().dir(compatSpecsDir.toString()));
+                task.getOutputResourceDir().set(projectLayout.getBuildDirectory().dir(compatSpecsDir.toString()));
                 task.setSourceResourceDir(
                     yamlCompatTestSourceSet.getResources()
                         .getSrcDirs()
@@ -102,17 +117,17 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
                 );
                 task.setSkipHasRestTestCheck(true);
                 task.setConfigToFileTree(
-                    config -> project.fileTree(
+                    config -> fileOperations.fileTree(
                         config.getSingleFile().toPath().resolve(RELATIVE_REST_API_RESOURCES).resolve(RELATIVE_API_PATH)
                     )
                 );
                 task.setAdditionalConfigToFileTree(
-                    config -> project.fileTree(
-                        getCompatProjectPath(project, config.getSingleFile().toPath()).resolve(RELATIVE_REST_PROJECT_RESOURCES)
+                    config -> fileOperations.fileTree(
+                        getCompatProjectPath(projectPath, config.getSingleFile().toPath()).resolve(RELATIVE_REST_PROJECT_RESOURCES)
                             .resolve(RELATIVE_API_PATH)
                     )
                 );
-                task.onlyIf(t -> isEnabled(project));
+                task.onlyIf(t -> isEnabled(extraProperties));
             });
 
         // copy compatible rest tests
@@ -124,30 +139,30 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
                 task.setAdditionalConfig(bwcMinorConfig);
                 task.getIncludeCore().set(extension.getRestTests().getIncludeCore());
                 task.getIncludeXpack().set(extension.getRestTests().getIncludeXpack());
-                task.getOutputResourceDir().set(project.getLayout().getBuildDirectory().dir(compatTestsDir.resolve("original").toString()));
+                task.getOutputResourceDir().set(projectLayout.getBuildDirectory().dir(compatTestsDir.resolve("original").toString()));
                 task.setCoreConfigToFileTree(
-                    config -> project.fileTree(
+                    config -> fileOperations.fileTree(
                         config.getSingleFile().toPath().resolve(RELATIVE_REST_API_RESOURCES).resolve(RELATIVE_TEST_PATH)
                     )
                 );
                 task.setXpackConfigToFileTree(
-                    config -> project.fileTree(
+                    config -> fileOperations.fileTree(
                         config.getSingleFile().toPath().resolve(RELATIVE_REST_XPACK_RESOURCES).resolve(RELATIVE_TEST_PATH)
                     )
                 );
                 task.setAdditionalConfigToFileTree(
-                    config -> project.fileTree(
-                        getCompatProjectPath(project, config.getSingleFile().toPath()).resolve(RELATIVE_REST_PROJECT_RESOURCES)
+                    config -> fileOperations.fileTree(
+                        getCompatProjectPath(projectPath, config.getSingleFile().toPath()).resolve(RELATIVE_REST_PROJECT_RESOURCES)
                             .resolve(RELATIVE_TEST_PATH)
                     )
                 );
                 task.dependsOn(copyCompatYamlSpecTask);
-                task.onlyIf(t -> isEnabled(project));
+                task.onlyIf(t -> isEnabled(extraProperties));
             });
 
         // copy both local source set apis and compat apis to a single location to be exported as an artifact
         TaskProvider<Sync> bundleRestCompatApis = project.getTasks().register("bundleRestCompatApis", Sync.class, task -> {
-            task.setDestinationDir(project.getLayout().getBuildDirectory().dir("bundledCompatApis").get().getAsFile());
+            task.setDestinationDir(projectLayout.getBuildDirectory().dir("bundledCompatApis").get().getAsFile());
             task.setIncludeEmptyDirs(false);
             task.from(copyCompatYamlSpecTask.flatMap(t -> t.getOutputResourceDir().map(d -> d.dir(RELATIVE_API_PATH.toString()))));
             task.from(yamlCompatTestSourceSet.getProcessResourcesTaskName(), s -> {
@@ -166,7 +181,7 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
                 task.getSourceDirectory().set(copyCompatYamlTestTask.flatMap(CopyRestTestsTask::getOutputResourceDir));
                 task.getOutputDirectory()
                     .set(project.getLayout().getBuildDirectory().dir(compatTestsDir.resolve("transformed").toString()));
-                task.onlyIf(t -> isEnabled(project));
+                task.onlyIf(t -> isEnabled(extraProperties));
             });
 
         // Register compat rest resources with source set
@@ -213,7 +228,7 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
 
             // run compatibility tests after "normal" tests
             testTask.mustRunAfter(project.getTasks().named(InternalYamlRestTestPlugin.SOURCE_SET_NAME));
-            testTask.onlyIf(t -> isEnabled(project));
+            testTask.onlyIf(t -> isEnabled(extraProperties));
         });
 
         setupYamlRestTestDependenciesDefaults(project, yamlCompatTestSourceSet);
@@ -235,13 +250,13 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
 
     }
 
-    private boolean isEnabled(Project project) {
-        Object bwcEnabled = project.getExtensions().getExtraProperties().getProperties().get("bwc_tests_enabled");
+    private boolean isEnabled(ExtraPropertiesExtension extraProperties) {
+        Object bwcEnabled = extraProperties.getProperties().get("bwc_tests_enabled");
         return bwcEnabled == null || (Boolean) bwcEnabled;
     }
 
     // TODO: implement custom extension that allows us move around of the projects between major versions and still find them
-    private Path getCompatProjectPath(Project project, Path checkoutDir) {
-        return checkoutDir.resolve(project.getPath().replaceFirst(":", "").replace(":", File.separator));
+    private Path getCompatProjectPath(String projectPath, Path checkoutDir) {
+        return checkoutDir.resolve(projectPath.replaceFirst(":", "").replace(":", File.separator));
     }
 }

+ 1 - 3
x-pack/build.gradle

@@ -21,10 +21,8 @@ subprojects {
   }
 
   group = 'org.elasticsearch.plugin'
-  ext.xpackRootProject = xpackRootProject
-  ext.xpackProject = { String projectName -> xpackRootProject.project(projectName) }
   // helper method to find the path to a module
-  ext.xpackModule = { String moduleName -> xpackProject("plugin:${moduleName}").path }
+  ext.xpackModule = { String moduleName -> ":x-pack:plugin:${moduleName}" }
 
   plugins.withType(PluginBuildPlugin).whenPluginAdded {
     project.esplugin.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE-2.0.txt')

+ 4 - 4
x-pack/docs/build.gradle

@@ -21,7 +21,7 @@ tasks.named("buildRestTests").configure {
 
 dependencies {
   yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
-  yamlRestTestImplementation(testArtifact(project(xpackProject('plugin').path)))
+  yamlRestTestImplementation(testArtifact(project(':x-pack:plugin')))
 }
 
 restResources {
@@ -31,9 +31,9 @@ restResources {
 }
 
 testClusters.matching { it.name == "yamlRestTest" }.configureEach {
-  extraConfigFile 'op-jwks.json', xpackProject('test:idp-fixture').file("oidc/op-jwks.json")
-  extraConfigFile 'idp-docs-metadata.xml', xpackProject('test:idp-fixture').file("idp/shibboleth-idp/metadata/idp-docs-metadata.xml")
-  extraConfigFile 'testClient.crt', xpackProject('plugin:security').file("src/test/resources/org/elasticsearch/xpack/security/action/pki_delegation/testClient.crt")
+  extraConfigFile 'op-jwks.json', project(':x-pack:test:idp-fixture').file("oidc/op-jwks.json")
+  extraConfigFile 'idp-docs-metadata.xml', project(':x-pack:test:idp-fixture').file("idp/shibboleth-idp/metadata/idp-docs-metadata.xml")
+  extraConfigFile 'testClient.crt', project(':x-pack:plugin:security').file("src/test/resources/org/elasticsearch/xpack/security/action/pki_delegation/testClient.crt")
   setting 'xpack.security.enabled', 'true'
   setting 'xpack.security.authc.api_key.enabled', 'true'
   setting 'xpack.security.authc.token.enabled', 'true'

+ 1 - 1
x-pack/plugin/async-search/build.gradle

@@ -8,7 +8,7 @@ esplugin {
 }
 archivesBaseName = 'x-pack-async-search'
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 dependencies {
   compileOnly project(":server")

+ 1 - 1
x-pack/plugin/autoscaling/build.gradle

@@ -21,4 +21,4 @@ dependencies {
   testImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/ccr/build.gradle

@@ -25,7 +25,7 @@ tasks.named('internalClusterTest').configure {
   exclude noSecurityManagerITClasses
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 dependencies {
   compileOnly project(":server")

+ 1 - 1
x-pack/plugin/deprecation/build.gradle

@@ -8,7 +8,7 @@ esplugin {
 }
 archivesBaseName = 'x-pack-deprecation'
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 dependencies {
   compileOnly project(":x-pack:plugin:core")

+ 1 - 1
x-pack/plugin/enrich/build.gradle

@@ -18,4 +18,4 @@ dependencies {
   testImplementation(testArtifact(project(xpackModule('monitoring'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/eql/build.gradle

@@ -39,7 +39,7 @@ dependencies {
  *  TODO: Enable for all builds upon this feature release       *
  ****************************************************************/
 if (BuildParams.isSnapshotBuild()) {
-  addQaCheckDependencies()
+  addQaCheckDependencies(project)
 }
 
 /**********************************************

+ 1 - 1
x-pack/plugin/graph/build.gradle

@@ -13,4 +13,4 @@ dependencies {
   testImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/identity-provider/build.gradle

@@ -289,7 +289,7 @@ tasks.named("thirdPartyAudit").configure {
   )
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 if (BuildParams.inFipsJvm) {
   // We don't support the IDP in FIPS-140 mode, so no need to run tests

+ 1 - 1
x-pack/plugin/ilm/build.gradle

@@ -19,7 +19,7 @@ dependencies {
   testImplementation project(':modules:data-streams')
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 tasks.named("test").configure {
   if (BuildParams.isSnapshotBuild() == false) {

+ 1 - 1
x-pack/plugin/ml/build.gradle

@@ -110,4 +110,4 @@ tasks.named("dependencyLicenses").configure {
   mapping from: /lucene-.*/, to: 'lucene'
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/ml/qa/ml-with-security/build.gradle

@@ -2,7 +2,7 @@ apply plugin: 'elasticsearch.internal-yaml-rest-test'
 
 dependencies {
   yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
-  yamlRestTestImplementation(testArtifact(xpackProject('plugin')))
+  yamlRestTestImplementation(testArtifact(project(':x-pack:plugin')))
 }
 
 // bring in machine learning rest test suite

+ 1 - 1
x-pack/plugin/old-lucene-versions/build.gradle

@@ -15,4 +15,4 @@ dependencies {
   internalClusterTestImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/repositories-metering-api/build.gradle

@@ -18,4 +18,4 @@ testClusters.configureEach {
   setting 'xpack.security.enabled', 'false'
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/rollup/build.gradle

@@ -19,7 +19,7 @@ dependencies {
   testImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 tasks.named("test").configure {
   if (BuildParams.isSnapshotBuild() == false) {

+ 1 - 1
x-pack/plugin/searchable-snapshots/build.gradle

@@ -18,7 +18,7 @@ dependencies {
   internalClusterTestImplementation(project(path: ':modules:reindex'))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 tasks.named("internalClusterTest").configure {
   // Reduce the buffer size per cache-fetch thread to keep direct memory usage under control.

+ 1 - 1
x-pack/plugin/security/build.gradle

@@ -429,4 +429,4 @@ tasks.named("internalClusterTest").configure {
   systemProperty 'es.transport.buffer.size', '256k'
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/shutdown/build.gradle

@@ -16,7 +16,7 @@ dependencies {
     testImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 testClusters.configureEach {
   testDistribution = 'default'

+ 1 - 1
x-pack/plugin/snapshot-based-recoveries/build.gradle

@@ -18,4 +18,4 @@ dependencies {
   internalClusterTestImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/snapshot-repo-test-kit/build.gradle

@@ -15,4 +15,4 @@ dependencies {
   internalClusterTestImplementation testArtifact(project(xpackModule('core')))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/sql/build.gradle

@@ -52,7 +52,7 @@ esplugin.bundleSpec.from({configurations.bin}) {
     into 'bin'
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 /**********************************************
  *          SQL Parser regeneration           *

+ 1 - 1
x-pack/plugin/sql/jdbc/build.gradle

@@ -11,7 +11,7 @@ tasks.named('forbiddenApisMain').configure {
 }
 
 dependencies {
-  api xpackProject('plugin:sql:sql-client')
+  api project(':x-pack:plugin:sql:sql-client')
   testImplementation project(":test:framework")
   testImplementation(testArtifact(project(xpackModule('core'))))
 }

+ 2 - 2
x-pack/plugin/sql/qa/jdbc/build.gradle

@@ -12,7 +12,7 @@ group = 'org.elasticsearch.x-pack.qa.sql.jdbc'
 
 dependencies {
   api project(':test:framework')
-  implementation xpackProject('plugin:sql:sql-proto')
+  implementation project(':x-pack:plugin:sql:sql-proto')
 
   // Actual tests will use the shadow jar
   compileOnly(project(path: xpackModule('sql:jdbc'))) {
@@ -55,7 +55,7 @@ subprojects {
     apply plugin: 'elasticsearch.internal-java-rest-test'
 
     dependencies {
-      javaRestTestImplementation(xpackProject('plugin:sql:qa:jdbc'))
+      javaRestTestImplementation(project(':x-pack:plugin:sql:qa:jdbc'))
       // We use the shadowjar for testing since that's the actual artifact we deliver to users
       javaRestTestCompileOnly project(path: xpackModule('sql:jdbc'), configuration: 'shadow')
     }

+ 1 - 1
x-pack/plugin/sql/qa/jdbc/security/build.gradle

@@ -4,7 +4,7 @@ apply plugin: 'elasticsearch.internal-test-artifact'
 
 dependencies {
   testImplementation project(':x-pack:plugin:core')
-  testImplementation(xpackProject('plugin:sql:qa:jdbc'))
+  testImplementation(project(':x-pack:plugin:sql:qa:jdbc'))
   // We use the shadowjar for testing since that's the actual artifact we deliver to users
   testCompileOnly project(path: xpackModule('sql:jdbc'), configuration: 'shadow')
 }

+ 3 - 3
x-pack/plugin/sql/qa/server/build.gradle

@@ -63,7 +63,7 @@ subprojects {
      * dependencies but we don't really want them because they cause
      * all kinds of trouble with the jar hell checks. So we suppress
      * them explicitly for non-es projects. */
-    javaRestTestImplementation(xpackProject('plugin:sql:qa:server')) {
+    javaRestTestImplementation(project(':x-pack:plugin:sql:qa:server')) {
       transitive = false
     }
     javaRestTestImplementation project(":test:framework")
@@ -81,11 +81,11 @@ subprojects {
 
 
     javaRestTestRuntimeOnly project(path: xpackModule('sql:jdbc'))
-    javaRestTestRuntimeOnly xpackProject('plugin:sql:sql-client')
+    javaRestTestRuntimeOnly project(':x-pack:plugin:sql:sql-client')
 
     // CLI testing dependencies
     javaRestTestRuntimeOnly project(path: xpackModule('sql:sql-cli'))
-    javaRestTestRuntimeOnly(xpackProject('plugin:sql:sql-action')) {
+    javaRestTestRuntimeOnly(project(':x-pack:plugin:sql:sql-action')) {
       transitive = false
     }
 

+ 1 - 1
x-pack/plugin/sql/qa/server/security/build.gradle

@@ -4,7 +4,7 @@ dependencies {
   testImplementation project(':x-pack:plugin:core')
   testImplementation(testArtifact(project(xpackModule('core'))))
   testImplementation project(":test:framework")
-  testImplementation(xpackProject('plugin:sql:qa:server')) {
+  testImplementation(project(':x-pack:plugin:sql:qa:server')) {
     transitive = false
   }
 }

+ 3 - 3
x-pack/plugin/sql/sql-action/build.gradle

@@ -17,9 +17,9 @@ dependencies {
   api(project(':libs:elasticsearch-x-content')) {
     transitive = false
   }
-  api xpackProject('plugin:core')
-  api xpackProject('plugin:ql')
-  api xpackProject('plugin:sql:sql-proto')
+  api project(':x-pack:plugin:core')
+  api project(':x-pack:plugin:ql')
+  api project(':x-pack:plugin:sql:sql-proto')
 
   testImplementation project(":test:framework")
   testImplementation(project(xpackModule('ql:test-fixtures')))

+ 1 - 1
x-pack/plugin/sql/sql-cli/build.gradle

@@ -26,7 +26,7 @@ dependencies {
   api "org.jline:jline-reader:${jlineVersion}"
   api "org.jline:jline-style:${jlineVersion}"
 
-  api xpackProject('plugin:sql:sql-client')
+  api project(':x-pack:plugin:sql:sql-client')
   api project(":libs:elasticsearch-cli")
   runtimeOnly "net.java.dev.jna:jna:${versions.jna}"
   testImplementation project(":test:framework")

+ 1 - 1
x-pack/plugin/sql/sql-client/build.gradle

@@ -7,7 +7,7 @@ apply plugin: 'elasticsearch.build'
 description = 'Code shared between jdbc and cli'
 
 dependencies {
-  api xpackProject('plugin:sql:sql-proto')
+  api project(':x-pack:plugin:sql:sql-proto')
   testImplementation project(":test:framework")
   testImplementation(testArtifact(project(xpackModule('core'))))
 }

+ 1 - 1
x-pack/plugin/stack/build.gradle

@@ -15,4 +15,4 @@ dependencies {
   testImplementation(testArtifact(project(xpackModule('core'))))
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/text-structure/build.gradle

@@ -15,6 +15,6 @@ dependencies {
   api "net.sf.supercsv:super-csv:${versions.supercsv}"
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)
 
 tasks.named("testingConventions").configure { enabled = false }

+ 1 - 1
x-pack/plugin/text-structure/qa/text-structure-with-security/build.gradle

@@ -2,7 +2,7 @@ apply plugin: 'elasticsearch.internal-yaml-rest-test'
 
 dependencies {
   yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
-  yamlRestTestImplementation(testArtifact(xpackProject('plugin')))
+  yamlRestTestImplementation(testArtifact(project(':x-pack:plugin')))
 }
 
 // bring in text structure rest test suite

+ 1 - 1
x-pack/plugin/transform/build.gradle

@@ -26,4 +26,4 @@ restResources {
   }
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/plugin/watcher/build.gradle

@@ -80,4 +80,4 @@ tasks.named("forbiddenPatterns").configure {
   exclude '**/*.p12'
 }
 
-addQaCheckDependencies()
+addQaCheckDependencies(project)

+ 1 - 1
x-pack/qa/openldap-tests/build.gradle

@@ -8,7 +8,7 @@ dependencies {
 
 testFixtures.useFixture ":x-pack:test:idp-fixture", "openldap"
 
-Project idpFixtureProject = xpackProject("test:idp-fixture")
+Project idpFixtureProject = project(":x-pack:test:idp-fixture")
 String outputDir = "${project.buildDir}/generated-resources/${project.name}"
 def copyIdpTrust = tasks.register("copyIdpTrust", Copy) {
   from idpFixtureProject.file('openldap/certs/ca.jks');

+ 1 - 1
x-pack/qa/runtime-fields/build.gradle

@@ -24,7 +24,7 @@ subprojects {
     apply plugin: 'elasticsearch.internal-yaml-rest-test'
 
     dependencies {
-      yamlRestTestImplementation xpackProject(":x-pack:qa:runtime-fields")
+      yamlRestTestImplementation project(":x-pack:qa:runtime-fields")
     }
 
     restResources {

+ 1 - 1
x-pack/qa/saml-idp-tests/build.gradle

@@ -1,6 +1,6 @@
 import org.elasticsearch.gradle.Architecture
 
-Project idpFixtureProject = xpackProject("test:idp-fixture")
+Project idpFixtureProject = project(':x-pack:test:idp-fixture')
 
 apply plugin: 'elasticsearch.internal-java-rest-test'
 apply plugin: 'elasticsearch.test.fixtures'

+ 2 - 2
x-pack/qa/xpack-prefix-rest-compat/build.gradle

@@ -28,7 +28,7 @@ int compatVersion = VersionProperties.getElasticsearchVersion().getMajor() - 1;
 
 dependencies {
   "yamlRestTestV${compatVersion}CompatImplementation" project(':test:framework')
-  "yamlRestTestV${compatVersion}CompatImplementation"(testArtifact(xpackProject('plugin')))
+  "yamlRestTestV${compatVersion}CompatImplementation"(testArtifact(project(':x-pack:plugin')))
   compatXpackTests project(path: ':x-pack:plugin', configuration: 'restCompatTests')
 }
 
@@ -39,7 +39,7 @@ tasks.named("copyRestCompatTestTask").configure { task ->
     task.getIncludeXpack().set(List.of("license", "migration", "ml", "rollup", "sql", "ssl"));
     task.getOutputResourceDir().set(project.getLayout().getBuildDirectory().dir("restResources/v${compatVersion}/yamlTests/original"));
     task.setXpackConfigToFileTree(
-      config -> project.fileTree(
+      config -> fileTree(
         config.getSingleFile().toPath()
       )
     )