diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index fe7fff9ad3e03..a32644fa6542c 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -61,7 +61,7 @@ Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('ver version = props.getProperty("opensearch") def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) { - outputFile = "${buildDir}/version.properties" + destinationFile = file("${buildDir}/version.properties") comment = 'Generated version properties' properties(props) } diff --git a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java index cdf22407f6076..451bd9cf83053 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java @@ -35,6 +35,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin; import org.opensearch.gradle.info.BuildParams; import org.opensearch.gradle.info.GlobalBuildInfoPlugin; +import org.opensearch.gradle.jvm.JvmTestSuiteHelper; import org.opensearch.gradle.test.ErrorReportingTestListener; import org.opensearch.gradle.util.Util; import org.gradle.api.Action; @@ -223,7 +224,15 @@ public void execute(Task t) { // Add the shadow JAR artifact itself FileCollection shadowJar = project.files(project.getTasks().named("shadowJar")); - test.setClasspath(test.getClasspath().minus(mainRuntime).plus(shadowConfig).plus(shadowJar)); + // See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath + test.setClasspath( + JvmTestSuiteHelper.getDefaultTestSuite(project) + .map(suite -> suite.getSources().getRuntimeClasspath()) + .orElseGet(() -> test.getClasspath()) + .minus(mainRuntime) + .plus(shadowConfig) + .plus(shadowJar) + ); }); }); } diff --git a/buildSrc/src/main/java/org/opensearch/gradle/jvm/JvmTestSuiteHelper.java b/buildSrc/src/main/java/org/opensearch/gradle/jvm/JvmTestSuiteHelper.java new file mode 100644 index 0000000000000..3b8e88c9f1a8f --- /dev/null +++ b/buildSrc/src/main/java/org/opensearch/gradle/jvm/JvmTestSuiteHelper.java @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.gradle.jvm; + +import org.gradle.api.Project; +import org.gradle.api.plugins.JvmTestSuitePlugin; +import org.gradle.api.plugins.jvm.JvmTestSuite; +import org.gradle.testing.base.TestSuite; +import org.gradle.testing.base.TestingExtension; + +import java.util.Optional; + +public final class JvmTestSuiteHelper { + private JvmTestSuiteHelper() {} + + /** + * Gets the default test suite. This method assumes the Java plugin is applied, + * adapted from {@link org.gradle.api.plugins.internal.JavaPluginHelper} since it is not + * available in Gradle releases predated 8.1. + */ + public static Optional getDefaultTestSuite(Project project) { + TestingExtension testing = project.getExtensions().findByType(TestingExtension.class); + if (testing == null) { + return Optional.empty(); + } + + TestSuite defaultTestSuite = testing.getSuites().findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME); + if (!(defaultTestSuite instanceof JvmTestSuite)) { + return Optional.empty(); + } + + return Optional.of((JvmTestSuite) defaultTestSuite); + } +} diff --git a/buildSrc/src/main/java/org/opensearch/gradle/precommit/TestingConventionsTasks.java b/buildSrc/src/main/java/org/opensearch/gradle/precommit/TestingConventionsTasks.java index 5e42cc99dd79e..dad3bfca5f67d 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/precommit/TestingConventionsTasks.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/precommit/TestingConventionsTasks.java @@ -32,6 +32,8 @@ package org.opensearch.gradle.precommit; import groovy.lang.Closure; + +import org.opensearch.gradle.jvm.JvmTestSuiteHelper; import org.opensearch.gradle.util.GradleUtils; import org.opensearch.gradle.util.Util; import org.gradle.api.DefaultTask; @@ -39,6 +41,7 @@ import org.gradle.api.Task; import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileTree; +import org.gradle.api.plugins.jvm.JvmTestSuite; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.OutputFile; @@ -46,6 +49,9 @@ import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.testing.Test; +import org.gradle.api.tasks.util.PatternFilterable; +import org.gradle.api.tasks.util.PatternSet; +import org.gradle.internal.Factory; import java.io.File; import java.io.IOException; @@ -70,6 +76,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.inject.Inject; + public class TestingConventionsTasks extends DefaultTask { private static final String TEST_METHOD_PREFIX = "test"; @@ -85,13 +93,39 @@ public TestingConventionsTasks() { naming = getProject().container(TestingConventionRule.class); } + @Inject + protected Factory getPatternSetFactory() { + throw new UnsupportedOperationException(); + } + @Input public Map> getClassFilesPerEnabledTask() { return getProject().getTasks() .withType(Test.class) .stream() .filter(Task::getEnabled) - .collect(Collectors.toMap(Task::getPath, task -> task.getCandidateClassFiles().getFiles())); + .collect(Collectors.toMap(Task::getPath, task -> { + // See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath + final JvmTestSuite jvmTestSuite = JvmTestSuiteHelper.getDefaultTestSuite(getProject()).orElse(null); + if (jvmTestSuite != null) { + final PatternFilterable patternSet = getPatternSetFactory().create() + .include(task.getIncludes()) + .exclude(task.getExcludes()); + + final Set files = jvmTestSuite.getSources() + .getOutput() + .getClassesDirs() + .getAsFileTree() + .matching(patternSet) + .getFiles(); + + if (!files.isEmpty()) { + return files; + } + } + + return task.getCandidateClassFiles().getFiles(); + })); } @Input diff --git a/buildSrc/src/main/java/org/opensearch/gradle/test/RestIntegTestTask.java b/buildSrc/src/main/java/org/opensearch/gradle/test/RestIntegTestTask.java index d1671146d0b77..87aa3ea4eae8d 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/test/RestIntegTestTask.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/test/RestIntegTestTask.java @@ -33,6 +33,10 @@ package org.opensearch.gradle.test; import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask; + +import groovy.lang.Closure; + +import org.gradle.api.Task; import org.gradle.api.tasks.CacheableTask; /** @@ -41,4 +45,12 @@ * conventional configured tasks of {@link RestIntegTestTask} */ @CacheableTask -public class RestIntegTestTask extends StandaloneRestIntegTestTask {} +public class RestIntegTestTask extends StandaloneRestIntegTestTask implements TestSuiteConventionMappings { + @SuppressWarnings("rawtypes") + @Override + public Task configure(Closure closure) { + final Task t = super.configure(closure); + applyConventionMapping(getProject(), getConventionMapping()); + return t; + } +} diff --git a/buildSrc/src/main/java/org/opensearch/gradle/test/TestSuiteConventionMappings.java b/buildSrc/src/main/java/org/opensearch/gradle/test/TestSuiteConventionMappings.java new file mode 100644 index 0000000000000..12096b8d365f4 --- /dev/null +++ b/buildSrc/src/main/java/org/opensearch/gradle/test/TestSuiteConventionMappings.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.gradle.test; + +import org.gradle.api.Project; +import org.gradle.api.internal.ConventionMapping; +import org.opensearch.gradle.jvm.JvmTestSuiteHelper; + +// Temporary workaround for https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath +interface TestSuiteConventionMappings { + default void applyConventionMapping(Project project, ConventionMapping conventionMapping) { + JvmTestSuiteHelper.getDefaultTestSuite(project).ifPresent(defaultTestSuite -> { + conventionMapping.map("testClassesDirs", () -> { return defaultTestSuite.getSources().getOutput().getClassesDirs(); }); + + conventionMapping.map("classpath", () -> { return defaultTestSuite.getSources().getRuntimeClasspath(); }); + }); + } +} diff --git a/buildSrc/src/main/java/org/opensearch/gradle/test/TestTask.java b/buildSrc/src/main/java/org/opensearch/gradle/test/TestTask.java new file mode 100644 index 0000000000000..837660d4618be --- /dev/null +++ b/buildSrc/src/main/java/org/opensearch/gradle/test/TestTask.java @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.gradle.test; + +import groovy.lang.Closure; + +import org.gradle.api.Task; +import org.gradle.api.tasks.CacheableTask; +import org.gradle.api.tasks.testing.Test; + +@CacheableTask +public class TestTask extends Test implements TestSuiteConventionMappings { + @SuppressWarnings("rawtypes") + @Override + public Task configure(Closure closure) { + final Task t = super.configure(closure); + applyConventionMapping(getProject(), getConventionMapping()); + return t; + } +} diff --git a/gradle/code-coverage.gradle b/gradle/code-coverage.gradle index 7f8af147e236c..d5a717b5ea720 100644 --- a/gradle/code-coverage.gradle +++ b/gradle/code-coverage.gradle @@ -19,7 +19,7 @@ repositories { allprojects { plugins.withId('jacoco') { - jacoco.toolVersion = '0.8.8' + jacoco.toolVersion = '0.8.9' } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7710dea..c1962a79e29d3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 21b7e71e15d65..9b615e6c35f01 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -11,7 +11,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=47a5bfed9ef814f90f8debcbbb315e8e7c654109acd224595ea39fca95c5d4da +distributionSha256Sum=2cbafcd2c47a101cb2165f636b4677fac0b954949c9429c1c988da399defe6a9 diff --git a/gradlew b/gradlew index 79a61d421cc4e..aeb74cbb43e39 100755 --- a/gradlew +++ b/gradlew @@ -85,9 +85,6 @@ done APP_BASE_NAME=${0##*/} APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/modules/transport-netty4/build.gradle b/modules/transport-netty4/build.gradle index a68d70d124094..4c245ec517bbd 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -31,6 +31,7 @@ import org.opensearch.gradle.info.BuildParams import org.opensearch.gradle.test.RestIntegTestTask +import org.opensearch.gradle.test.TestTask import org.opensearch.gradle.test.rest.JavaRestTestPlugin import org.opensearch.gradle.test.InternalClusterTestPlugin @@ -92,13 +93,13 @@ javaRestTest { systemProperty 'opensearch.set.netty.runtime.available.processors', 'false' } -TaskProvider pooledTest = tasks.register("pooledTest", Test) { +TaskProvider pooledTest = tasks.register("pooledTest", TestTask) { include '**/*Tests.class' systemProperty 'opensearch.set.netty.runtime.available.processors', 'false' systemProperty 'opensearch.use_unpooled_allocator', 'false' } -TaskProvider pooledInternalClusterTest = tasks.register("pooledInternalClusterTest", Test) { +TaskProvider pooledInternalClusterTest = tasks.register("pooledInternalClusterTest", TestTask) { include '**/*IT.class' systemProperty 'opensearch.set.netty.runtime.available.processors', 'false' systemProperty 'opensearch.use_unpooled_allocator', 'false' diff --git a/plugins/repository-hdfs/build.gradle b/plugins/repository-hdfs/build.gradle index c1bb9181df151..c1aaa184d59db 100644 --- a/plugins/repository-hdfs/build.gradle +++ b/plugins/repository-hdfs/build.gradle @@ -227,7 +227,8 @@ for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSec .resolve("ports") } nonInputProperties.systemProperty "test.hdfs-fixture.ports", file("$portsFileDir/ports") - classpath += files(portsFileDir) + // See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath + classpath = testing.suites.test.sources.runtimeClasspath + files(portsFileDir) // Copy ports file to separate location which is placed on the test classpath doFirst { mkdir(portsFileDir) diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle index de9617d7bb608..9e239950cac69 100644 --- a/plugins/repository-s3/build.gradle +++ b/plugins/repository-s3/build.gradle @@ -31,6 +31,7 @@ import org.opensearch.gradle.MavenFilteringHack import org.opensearch.gradle.info.BuildParams import org.opensearch.gradle.test.RestIntegTestTask +import org.opensearch.gradle.test.TestTask import org.opensearch.gradle.test.rest.YamlRestTestPlugin import org.opensearch.gradle.test.InternalClusterTestPlugin @@ -86,7 +87,7 @@ bundlePlugin { } } -task testRepositoryCreds(type: Test) { +task testRepositoryCreds(type: TestTask) { include '**/RepositoryCredentialsTests.class' systemProperty 'opensearch.allow_insecure_settings', 'true' } diff --git a/qa/wildfly/build.gradle b/qa/wildfly/build.gradle index 353f9d54f91e3..75c94e7843e07 100644 --- a/qa/wildfly/build.gradle +++ b/qa/wildfly/build.gradle @@ -30,6 +30,7 @@ import org.opensearch.gradle.Architecture import org.opensearch.gradle.VersionProperties +import org.opensearch.gradle.test.TestTask apply plugin: 'war' apply plugin: 'opensearch.build' @@ -81,7 +82,7 @@ dockerCompose { useComposeFiles = ['docker-compose.yml'] } -tasks.register("integTest", Test) { +tasks.register("integTest", TestTask) { outputs.doNotCacheIf('Build cache is disabled for Docker tests') { true } maxParallelForks = '1' include '**/*IT.class'