Skip to content

Commit

Permalink
Update to Gradle 8.1
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Mar 30, 2023
1 parent d8d6e73 commit fd53cae
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ plugins {
id 'opensearch.docker-support'
id 'opensearch.global-build-info'
id "com.diffplug.spotless" version "6.17.0" apply false
id "org.gradle.test-retry" version "1.5.1" apply false
id "org.gradle.test-retry" version "1.5.2" apply false
id "test-report-aggregation"
id 'jacoco-report-aggregation'
}
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ dependencies {
api 'org.jdom:jdom2:2.0.6.1'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${props.getProperty('kotlin')}"
api 'de.thetaphi:forbiddenapis:3.4'
api 'com.avast.gradle:gradle-docker-compose-plugin:0.16.11'
api 'com.avast.gradle:gradle-docker-compose-plugin:0.16.12'
api "org.yaml:snakeyaml:${props.getProperty('snakeyaml')}"
api 'org.apache.maven:maven-model:3.9.1'
api 'com.networknt:json-schema-validator:1.0.78'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@
import org.opensearch.gradle.test.ErrorReportingTestListener;
import org.opensearch.gradle.util.Util;
import org.gradle.api.Action;
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JvmTestSuitePlugin;
import org.gradle.api.plugins.jvm.JvmTestSuite;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.testing.Test;
import org.gradle.testing.base.TestingExtension;
import org.gradle.testing.base.TestSuite;

import java.io.File;
import java.util.HashMap;
Expand Down Expand Up @@ -223,7 +228,24 @@ 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-rc-1/userguide/upgrading_version_8.html#test_task_default_classpath
boolean isClasspathSet = false;
final TestingExtension testing = project.getExtensions().findByType(TestingExtension.class);
if (testing != null) {
final ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
final TestSuite suite = testSuites.findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);
if (suite != null && suite instanceof JvmTestSuite) {
final JvmTestSuite jvmTestSuite = (JvmTestSuite) suite;
test.setClasspath(
jvmTestSuite.getSources().getRuntimeClasspath().minus(mainRuntime).plus(shadowConfig).plus(shadowJar)
);
isClasspathSet = true;
}
}

if (!isClasspathSet) {
test.setClasspath(test.getClasspath().minus(mainRuntime).plus(shadowConfig).plus(shadowJar));
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,25 @@
import org.opensearch.gradle.util.GradleUtils;
import org.opensearch.gradle.util.Util;
import org.gradle.api.DefaultTask;
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.JvmTestSuitePlugin;
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;
import org.gradle.api.tasks.SourceSet;
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 org.gradle.testing.base.TestSuite;
import org.gradle.testing.base.TestingExtension;

import java.io.File;
import java.io.IOException;
Expand All @@ -70,6 +78,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";
Expand All @@ -85,13 +95,42 @@ public TestingConventionsTasks() {
naming = getProject().container(TestingConventionRule.class);
}

@Inject
protected Factory<PatternSet> getPatternSetFactory() {
throw new UnsupportedOperationException();
}

@Input
public Map<String, Set<File>> 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-rc-1/userguide/upgrading_version_8.html#test_task_default_classpath
final TestingExtension testing = task.getProject().getExtensions().findByType(TestingExtension.class);
if (testing != null) {
final ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
final TestSuite suite = testSuites.findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);
if (suite != null && suite instanceof JvmTestSuite) {
final JvmTestSuite jvmTestSuite = (JvmTestSuite) suite;
final PatternFilterable patternSet = getPatternSetFactory().create()
.include(task.getIncludes())
.exclude(task.getExcludes());
final Set<File> files = jvmTestSuite.getSources()
.getOutput()
.getClassesDirs()
.getAsFileTree()
.matching(patternSet)
.getFiles();
if (!files.isEmpty()) {
return files;
}
}
}

return task.getCandidateClassFiles().getFiles();
}));
}

@Input
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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-rc-2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=47a5bfed9ef814f90f8debcbbb315e8e7c654109acd224595ea39fca95c5d4da
distributionSha256Sum=fd27a72140d0cc8cbf70f337d59e4c39da117edbc1b15f3847c0c419aff11ff3
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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-rc-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)
Expand Down

0 comments on commit fd53cae

Please sign in to comment.