diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/PrecommitTaskPlugin.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/PrecommitTaskPlugin.java index 0493b30149bf3..f6a5db279792c 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/PrecommitTaskPlugin.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/PrecommitTaskPlugin.java @@ -12,7 +12,7 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.plugins.JavaBasePlugin; -import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.testing.Test; import org.gradle.language.base.plugins.LifecycleBasePlugin; @@ -33,7 +33,7 @@ public void apply(Project project) { ); project.getPluginManager().withPlugin("java", p -> { // run compilation as part of precommit - project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> + project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(sourceSet -> precommit.configure(t -> t.shouldRunAfter(sourceSet.getClassesTaskName())) ); // make sure tests run after all precommit tasks diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java new file mode 100644 index 0000000000000..0ee68adb699c4 --- /dev/null +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaBasePlugin.java @@ -0,0 +1,122 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.gradle.internal; + +import org.elasticsearch.gradle.VersionProperties; +import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitTaskPlugin; +import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin; +import org.elasticsearch.gradle.internal.info.BuildParams; +import org.elasticsearch.gradle.util.GradleUtils; +import org.gradle.api.Action; +import org.gradle.api.JavaVersion; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ResolutionStrategy; +import org.gradle.api.plugins.JavaBasePlugin; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.compile.AbstractCompile; +import org.gradle.api.tasks.compile.CompileOptions; +import org.gradle.api.tasks.compile.GroovyCompile; +import org.gradle.api.tasks.compile.JavaCompile; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + + +/** + * A wrapper around Gradle's Java Base plugin that applies our + * common configuration for production code. + */ +public class ElasticsearchJavaBasePlugin implements Plugin { + @Override + public void apply(Project project) { + // make sure the global build info plugin is applied to the root project + project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class); + // common repositories setup + project.getPluginManager().apply(JavaBasePlugin.class); + project.getPluginManager().apply(RepositoriesSetupPlugin.class); + project.getPluginManager().apply(ElasticsearchTestBasePlugin.class); + project.getPluginManager().apply(PrecommitTaskPlugin.class); + + configureCompile(project); + configureInputNormalization(project); + + // convenience access to common versions used in dependencies + project.getExtensions().getExtraProperties().set("versions", VersionProperties.getVersions()); + } + + /** + * Adds compiler settings to the project + */ + public static void configureCompile(Project project) { + project.getExtensions().getExtraProperties().set("compactProfile", "full"); + + JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class); + java.setSourceCompatibility(BuildParams.getMinimumRuntimeVersion()); + java.setTargetCompatibility(BuildParams.getMinimumRuntimeVersion()); + + project.afterEvaluate(p -> { + project.getTasks().withType(JavaCompile.class).configureEach(compileTask -> { + CompileOptions compileOptions = compileTask.getOptions(); + /* + * -path because gradle will send in paths that don't always exist. + * -missing because we have tons of missing @returns and @param. + * -serial because we don't use java serialization. + */ + // don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :) + // fail on all javac warnings. + // TODO Discuss moving compileOptions.getCompilerArgs() to use provider api with Gradle team. + List compilerArgs = compileOptions.getCompilerArgs(); + compilerArgs.add("-Werror"); + compilerArgs.add("-Xlint:all,-path,-serial,-options,-deprecation,-try"); + compilerArgs.add("-Xdoclint:all"); + compilerArgs.add("-Xdoclint:-missing"); + // either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly + // defined + if (compilerArgs.contains("-processor") == false) { + compilerArgs.add("-proc:none"); + } + + compileOptions.setEncoding("UTF-8"); + compileOptions.setIncremental(true); + // workaround for https://github.com/gradle/gradle/issues/14141 + compileTask.getConventionMapping().map("sourceCompatibility", () -> java.getSourceCompatibility().toString()); + compileTask.getConventionMapping().map("targetCompatibility", () -> java.getTargetCompatibility().toString()); + compileOptions.getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask)); + }); + // also apply release flag to groovy, which is used in build-tools + project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> { + // TODO: this probably shouldn't apply to groovy at all? + compileTask.getOptions().getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask)); + }); + }); + } + + + /** + * Apply runtime classpath input normalization so that changes in JAR manifests don't break build cacheability + */ + public static void configureInputNormalization(Project project) { + project.getNormalization().getRuntimeClasspath().ignore("META-INF/MANIFEST.MF"); + } + + private static Provider releaseVersionProviderFromCompileTask(Project project, AbstractCompile compileTask) { + return project.provider(() -> { + JavaVersion javaVersion = JavaVersion.toVersion(compileTask.getTargetCompatibility()); + return Integer.parseInt(javaVersion.getMajorVersion()); + }); + } + +} diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java index d45e3b6236032..0c486ed8db43c 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java @@ -12,8 +12,6 @@ import nebula.plugin.info.InfoBrokerPlugin; import org.elasticsearch.gradle.VersionProperties; import org.elasticsearch.gradle.internal.info.BuildParams; -import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin; -import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitTaskPlugin; import org.elasticsearch.gradle.util.GradleUtils; import org.elasticsearch.gradle.internal.conventions.util.Util; import org.gradle.api.Action; @@ -52,28 +50,20 @@ import static org.elasticsearch.gradle.internal.conventions.util.Util.toStringable; /** - * A wrapper around Gradle's Java plugin that applies our common configuration. + * A wrapper around Gradle's Java plugin that applies our + * common configuration for production code. */ public class ElasticsearchJavaPlugin implements Plugin { @Override public void apply(Project project) { - // make sure the global build info plugin is applied to the root project - project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class); - // common repositories setup - project.getPluginManager().apply(RepositoriesSetupPlugin.class); + project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class); project.getPluginManager().apply(JavaLibraryPlugin.class); - project.getPluginManager().apply(ElasticsearchTestBasePlugin.class); - project.getPluginManager().apply(PrecommitTaskPlugin.class); configureConfigurations(project); - configureCompile(project); - configureInputNormalization(project); configureJars(project); configureJarManifest(project); configureJavadoc(project); - - // convenience access to common versions used in dependencies - project.getExtensions().getExtraProperties().set("versions", VersionProperties.getVersions()); + testCompileOnlyDeps(project); } /** @@ -93,11 +83,6 @@ public void apply(Project project) { * to iterate the transitive dependencies and add excludes. */ public static void configureConfigurations(Project project) { - // we want to test compileOnly deps! - Configuration compileOnlyConfig = project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); - Configuration testImplementationConfig = project.getConfigurations().getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); - testImplementationConfig.extendsFrom(compileOnlyConfig); - // we are not shipping these jars, we act like dumb consumers of these things if (project.getPath().startsWith(":test:fixtures") || project.getPath().equals(":build-tools")) { return; @@ -111,119 +96,57 @@ public static void configureConfigurations(Project project) { configuration.resolutionStrategy(ResolutionStrategy::failOnVersionConflict); }); - // force all dependencies added directly to compile/testImplementation to be non-transitive, except for ES itself - Consumer disableTransitiveDeps = configName -> { - Configuration config = project.getConfigurations().getByName(configName); - config.getDependencies().all(dep -> { - if (dep instanceof ModuleDependency - && dep instanceof ProjectDependency == false - && dep.getGroup().startsWith("org.elasticsearch") == false) { - ((ModuleDependency) dep).setTransitive(false); - } - }); - }; - // disable transitive dependency management SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); sourceSets.all(sourceSet -> disableTransitiveDependenciesForSourceSet(project, sourceSet)); } - /** - * Adds compiler settings to the project - */ - public static void configureCompile(Project project) { - project.getExtensions().getExtraProperties().set("compactProfile", "full"); - - JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class); - java.setSourceCompatibility(BuildParams.getMinimumRuntimeVersion()); - java.setTargetCompatibility(BuildParams.getMinimumRuntimeVersion()); - - project.afterEvaluate(p -> { - project.getTasks().withType(JavaCompile.class).configureEach(compileTask -> { - CompileOptions compileOptions = compileTask.getOptions(); - /* - * -path because gradle will send in paths that don't always exist. - * -missing because we have tons of missing @returns and @param. - * -serial because we don't use java serialization. - */ - // don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :) - // fail on all javac warnings. - // TODO Discuss moving compileOptions.getCompilerArgs() to use provider api with Gradle team. - List compilerArgs = compileOptions.getCompilerArgs(); - compilerArgs.add("-Werror"); - compilerArgs.add("-Xlint:all,-path,-serial,-options,-deprecation,-try"); - compilerArgs.add("-Xdoclint:all"); - compilerArgs.add("-Xdoclint:-missing"); - // either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly - // defined - if (compilerArgs.contains("-processor") == false) { - compilerArgs.add("-proc:none"); - } - - compileOptions.setEncoding("UTF-8"); - compileOptions.setIncremental(true); - // workaround for https://github.com/gradle/gradle/issues/14141 - compileTask.getConventionMapping().map("sourceCompatibility", () -> java.getSourceCompatibility().toString()); - compileTask.getConventionMapping().map("targetCompatibility", () -> java.getTargetCompatibility().toString()); - compileOptions.getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask)); - }); - // also apply release flag to groovy, which is used in build-tools - project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> { - // TODO: this probably shouldn't apply to groovy at all? - compileTask.getOptions().getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask)); - }); - }); - } - - private static Provider releaseVersionProviderFromCompileTask(Project project, AbstractCompile compileTask) { - return project.provider(() -> { - JavaVersion javaVersion = JavaVersion.toVersion(compileTask.getTargetCompatibility()); - return Integer.parseInt(javaVersion.getMajorVersion()); - }); - } - - /** - * Apply runtime classpath input normalization so that changes in JAR manifests don't break build cacheability - */ - public static void configureInputNormalization(Project project) { - project.getNormalization().getRuntimeClasspath().ignore("META-INF/MANIFEST.MF"); + private static void testCompileOnlyDeps(Project project) { + // we want to test compileOnly deps! + Configuration compileOnlyConfig = project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME); + Configuration testImplementationConfig = project.getConfigurations().getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); + testImplementationConfig.extendsFrom(compileOnlyConfig); } /** * Adds additional manifest info to jars */ static void configureJars(Project project) { - project.getTasks().withType(Jar.class).configureEach(jarTask -> { - // we put all our distributable files under distributions - jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions")); - // fixup the jar manifest - // Explicitly using an Action interface as java lambdas - // are not supported by Gradle up-to-date checks - jarTask.doFirst(new Action() { - @Override - public void execute(Task task) { - // this doFirst is added before the info plugin, therefore it will run - // after the doFirst added by the info plugin, and we can override attributes - jarTask.getManifest() - .attributes( - Map.of("Build-Date", BuildParams.getBuildDate(), "Build-Java-Version", BuildParams.getGradleJavaVersion()) - ); - } - }); - }); + project.getTasks().withType(Jar.class).configureEach( + jarTask -> { + // we put all our distributable files under distributions + jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions")); + // fixup the jar manifest + // Explicitly using an Action interface as java lambdas + // are not supported by Gradle up-to-date checks + jarTask.doFirst(new Action() { + @Override + public void execute(Task task) { + // this doFirst is added before the info plugin, therefore it will run + // after the doFirst added by the info plugin, and we can override attributes + jarTask.getManifest() + .attributes( + Map.of("Build-Date", BuildParams.getBuildDate(), "Build-Java-Version", BuildParams.getGradleJavaVersion() + ) + ); + } + }); + } + ); project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> { project.getTasks().withType(ShadowJar.class).configureEach(shadowJar -> { - /* - * Replace the default "-all" classifier with null - * which will leave the classifier off of the file name. - */ - shadowJar.getArchiveClassifier().set((String) null); - /* - * Not all cases need service files merged but it is - * better to be safe - */ - shadowJar.mergeServiceFiles(); - }); + /* + * Replace the default "-all" classifier with null + * which will leave the classifier off of the file name. + */ + shadowJar.getArchiveClassifier().set((String) null); + /* + * Not all cases need service files merged but it is + * better to be safe + */ + shadowJar.mergeServiceFiles(); + } + ); // Add "original" classifier to the non-shadowed JAR to distinguish it from the shadow JAR project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class).configure(jar -> jar.getArchiveClassifier().set("original")); // Make sure we assemble the shadow jar @@ -274,6 +197,7 @@ private static void disableTransitiveDependenciesForSourceSet(Project project, S Stream.of( sourceSet.getApiConfigurationName(), sourceSet.getImplementationConfigurationName(), + sourceSet.getImplementationConfigurationName(), sourceSet.getCompileOnlyConfigurationName(), sourceSet.getRuntimeOnlyConfigurationName() ) @@ -281,4 +205,5 @@ private static void disableTransitiveDependenciesForSourceSet(Project project, S .filter(Objects::nonNull) .forEach(GradleUtils::disableTransitiveDependencies); } + } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneRestTestPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneRestTestPlugin.java index e97b2299ba5b2..020fbdb941200 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneRestTestPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneRestTestPlugin.java @@ -8,6 +8,7 @@ package org.elasticsearch.gradle.internal.test; +import org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin; import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin; import org.elasticsearch.gradle.internal.ExportElasticsearchBuildResourcesTask; import org.elasticsearch.gradle.internal.RepositoriesSetupPlugin; @@ -46,17 +47,12 @@ public void apply(final Project project) { } project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class); - project.getPluginManager().apply(JavaBasePlugin.class); + project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class); project.getPluginManager().apply(TestClustersPlugin.class); project.getPluginManager().apply(RepositoriesSetupPlugin.class); project.getPluginManager().apply(RestTestBasePlugin.class); project.getTasks().register("buildResources", ExportElasticsearchBuildResourcesTask.class); - ElasticsearchJavaPlugin.configureInputNormalization(project); - ElasticsearchJavaPlugin.configureCompile(project); - - project.getExtensions().getByType(JavaPluginExtension.class).setSourceCompatibility(BuildParams.getMinimumRuntimeVersion()); - project.getExtensions().getByType(JavaPluginExtension.class).setTargetCompatibility(BuildParams.getMinimumRuntimeVersion()); // only setup tests to build SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneTestPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneTestPlugin.java index 5614b7d2f215c..a7bfd81695d14 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneTestPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/StandaloneTestPlugin.java @@ -30,7 +30,6 @@ public void apply(final Project project) { test.mustRunAfter(project.getTasks().getByName("precommit")); }); - ElasticsearchJavaPlugin.configureCompile(project); project.getTasks().named("check").configure(task -> task.dependsOn(project.getTasks().named("test"))); } } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/JavaRestTestPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/JavaRestTestPlugin.java index 1886bb0e6f168..b0539ca276786 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/JavaRestTestPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/JavaRestTestPlugin.java @@ -8,7 +8,7 @@ package org.elasticsearch.gradle.internal.test.rest; -import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin; +import org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin; import org.elasticsearch.gradle.internal.InternalTestClustersPlugin; import org.elasticsearch.gradle.internal.test.RestIntegTestTask; import org.elasticsearch.gradle.internal.test.RestTestBasePlugin; @@ -33,7 +33,7 @@ public class JavaRestTestPlugin implements Plugin { @Override public void apply(Project project) { - project.getPluginManager().apply(ElasticsearchJavaPlugin.class); + project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class); project.getPluginManager().apply(RestTestBasePlugin.class); project.getPluginManager().apply(InternalTestClustersPlugin.class); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestResourcesPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestResourcesPlugin.java index 0d961e7c3a1dd..9a8c910bf39ca 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestResourcesPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestResourcesPlugin.java @@ -83,7 +83,7 @@ public void apply(Project project) { RestResourcesExtension extension = project.getExtensions().create(EXTENSION_NAME, RestResourcesExtension.class); SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); - SourceSet defaultSourceSet = sourceSets.getByName(TEST_SOURCE_SET_NAME); + SourceSet defaultSourceSet = sourceSets.maybeCreate(TEST_SOURCE_SET_NAME); // tests Configuration testConfig = project.getConfigurations().create("restTestConfig"); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestUtil.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestUtil.java index aa073d273beb3..9f407e634df82 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestUtil.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestUtil.java @@ -17,11 +17,13 @@ import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; import org.gradle.api.plugins.JavaBasePlugin; +import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.bundling.Zip; +import org.gradle.api.tasks.testing.Test; /** * Utility class to configure the necessary tasks and dependencies. @@ -48,7 +50,10 @@ public static Provider registerTask(Project project, SourceSe Provider testProvider = project.getTasks().register(sourceSet.getName(), RestIntegTestTask.class, testTask -> { testTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP); testTask.setDescription("Runs the REST tests against an external cluster"); - testTask.mustRunAfter(project.getTasks().named("test")); + project.getPlugins().withType(JavaPlugin.class, t -> + testTask.mustRunAfter(project.getTasks().named("test")) + ); + testTask.setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); testTask.setClasspath(sourceSet.getRuntimeClasspath()); // if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/YamlRestTestPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/YamlRestTestPlugin.java index bd794d465b08c..d07c533293ecc 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/YamlRestTestPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/YamlRestTestPlugin.java @@ -8,6 +8,7 @@ package org.elasticsearch.gradle.internal.test.rest; +import org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin; import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin; import org.elasticsearch.gradle.internal.test.RestIntegTestTask; import org.elasticsearch.gradle.internal.test.RestTestBasePlugin; @@ -34,11 +35,12 @@ public class YamlRestTestPlugin implements Plugin { @Override public void apply(Project project) { - project.getPluginManager().apply(ElasticsearchJavaPlugin.class); + project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class); project.getPluginManager().apply(TestClustersPlugin.class); project.getPluginManager().apply(RestTestBasePlugin.class); project.getPluginManager().apply(RestResourcesPlugin.class); + ElasticsearchJavaPlugin.configureConfigurations(project); // create source set SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); SourceSet yamlTestSourceSet = sourceSets.create(SOURCE_SET_NAME); diff --git a/x-pack/plugin/ilm/qa/multi-node/build.gradle b/x-pack/plugin/ilm/qa/multi-node/build.gradle index d666fc10fb0a6..cd37b553a1772 100644 --- a/x-pack/plugin/ilm/qa/multi-node/build.gradle +++ b/x-pack/plugin/ilm/qa/multi-node/build.gradle @@ -7,10 +7,6 @@ dependencies { javaRestTestImplementation(testArtifact(project(xpackModule('core')))) } -// let the javaRestTest see the classpath of main -GradleUtils.extendSourceSet(project, "main", "javaRestTest", tasks.named("javaRestTest")) - - File repoDir = file("$buildDir/testclusters/repo") tasks.named("javaRestTest").configure { diff --git a/x-pack/plugin/ilm/qa/with-security/build.gradle b/x-pack/plugin/ilm/qa/with-security/build.gradle index 073e7e6abece7..a97f0aef1bcf0 100644 --- a/x-pack/plugin/ilm/qa/with-security/build.gradle +++ b/x-pack/plugin/ilm/qa/with-security/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'elasticsearch.java-rest-test' dependencies { javaRestTestImplementation project(path: xpackModule('core')) javaRestTestImplementation(testArtifact(project(xpackProject('plugin').path))) - testImplementation project(":client:rest-high-level") + javaRestTestImplementation project(":client:rest-high-level") } def clusterCredentials = [username: System.getProperty('tests.rest.cluster.username', 'test_admin'), diff --git a/x-pack/plugin/rollup/qa/rest/build.gradle b/x-pack/plugin/rollup/qa/rest/build.gradle index 80214bb60185c..e3cb2b9722e6c 100644 --- a/x-pack/plugin/rollup/qa/rest/build.gradle +++ b/x-pack/plugin/rollup/qa/rest/build.gradle @@ -26,8 +26,6 @@ testClusters.all { setting 'xpack.security.enabled', 'false' } -tasks.named("test").configure{enabled = false } - if (BuildParams.inFipsJvm){ // This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC tasks.named("yamlRestTest").configure{enabled = false } diff --git a/x-pack/plugin/security/qa/service-account/build.gradle b/x-pack/plugin/security/qa/service-account/build.gradle index cee72d1dba1cb..0f2253d9e7a74 100644 --- a/x-pack/plugin/security/qa/service-account/build.gradle +++ b/x-pack/plugin/security/qa/service-account/build.gradle @@ -4,8 +4,6 @@ dependencies { javaRestTestImplementation project(':x-pack:plugin:core') javaRestTestImplementation project(':client:rest-high-level') javaRestTestImplementation project(':x-pack:plugin:security') - // let the javaRestTest see the classpath of main - javaRestTestImplementation project.sourceSets.main.runtimeClasspath } testClusters.javaRestTest { diff --git a/x-pack/plugin/security/qa/tls-basic/build.gradle b/x-pack/plugin/security/qa/tls-basic/build.gradle index 677dc9ab4cc2f..c297ff01c263f 100644 --- a/x-pack/plugin/security/qa/tls-basic/build.gradle +++ b/x-pack/plugin/security/qa/tls-basic/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'elasticsearch.java-rest-test' import org.elasticsearch.gradle.internal.info.BuildParams dependencies { - testImplementation(testArtifact(project(xpackModule('security')))) - testImplementation(testArtifact(project(xpackModule('core')))) + javaRestTestImplementation(testArtifact(project(xpackModule('security')))) + javaRestTestImplementation(testArtifact(project(xpackModule('core')))) } if (BuildParams.inFipsJvm){ diff --git a/x-pack/plugin/transform/qa/multi-node-tests/build.gradle b/x-pack/plugin/transform/qa/multi-node-tests/build.gradle index 1706b0ae48c74..aa7a07c166754 100644 --- a/x-pack/plugin/transform/qa/multi-node-tests/build.gradle +++ b/x-pack/plugin/transform/qa/multi-node-tests/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'elasticsearch.java-rest-test' dependencies { javaRestTestImplementation(testArtifact(project(xpackModule('core')))) javaRestTestImplementation project(path: xpackModule('transform')) - testImplementation project(':client:rest-high-level') + javaRestTestImplementation project(':client:rest-high-level') } // location for keys and certificates @@ -17,11 +17,10 @@ tasks.register("copyKeyCerts", Copy) { } into keystoreDir } -// Add keys and cets to test classpath: it expects it there -sourceSets.test.resources.srcDir(keystoreDir) -tasks.named("processTestResources").configure { dependsOn("copyKeyCerts") } -tasks.named("processJavaRestTestResources").configure { dependsOn("copyKeyCerts") } +// Add keys and cets to javaRestTest classpath: it expects it there +sourceSets.javaRestTest.resources.srcDir(keystoreDir) +tasks.named("processJavaRestTestResources").configure { dependsOn("copyKeyCerts") } tasks.named("javaRestTest").configure { dependsOn "copyKeyCerts" } testClusters.javaRestTest { diff --git a/x-pack/plugin/transform/qa/single-node-tests/build.gradle b/x-pack/plugin/transform/qa/single-node-tests/build.gradle index d36eb871601a7..f4a194eb83fbb 100644 --- a/x-pack/plugin/transform/qa/single-node-tests/build.gradle +++ b/x-pack/plugin/transform/qa/single-node-tests/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'elasticsearch.java-rest-test' dependencies { javaRestTestImplementation(testArtifact(project(xpackModule('core')))) javaRestTestImplementation project(path: xpackModule('transform')) - testImplementation project(':client:rest-high-level') + javaRestTestImplementation project(':client:rest-high-level') } testClusters.all {