Skip to content

Commit 7914c04

Browse files
authored
Update Gradle to 8.0 (opensearch-project#5666)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent 8d6ef37 commit 7914c04

File tree

24 files changed

+129
-46
lines changed

24 files changed

+129
-46
lines changed

build.gradle

+15-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import org.gradle.plugins.ide.eclipse.model.AccessRule
4545
import org.gradle.plugins.ide.eclipse.model.EclipseJdt
4646
import org.gradle.plugins.ide.eclipse.model.SourceFolder
4747
import org.gradle.api.Project;
48+
import org.gradle.api.internal.tasks.testing.junit.JUnitTestFramework
4849
import org.gradle.process.ExecResult;
4950
import org.gradle.util.DistributionLocator
5051
import org.gradle.util.GradleVersion
@@ -56,7 +57,7 @@ plugins {
5657
id 'opensearch.docker-support'
5758
id 'opensearch.global-build-info'
5859
id "com.diffplug.spotless" version "6.11.0" apply false
59-
id "org.gradle.test-retry" version "1.4.1" apply false
60+
id "org.gradle.test-retry" version "1.5.1" apply false
6061
id "test-report-aggregation"
6162
id 'jacoco-report-aggregation'
6263
}
@@ -77,6 +78,19 @@ allprojects {
7778
group = 'org.opensearch'
7879
version = VersionProperties.getOpenSearch()
7980
description = "OpenSearch subproject ${project.path}"
81+
82+
afterEvaluate {
83+
project.tasks.withType(Test) { task ->
84+
// This is so hacky: now, by default, test tasks uses JUnit framework and always includes 'junit'
85+
// JARs from the Gradle distribution (no ways to override this behavior). It causes JAR hell on test
86+
// classpath, example of the report:
87+
//
88+
// jar1: /home/ubuntu/.gradle/caches/modules-2/files-2.1/junit/junit/4.13.2/8ac9e16d933b6fb43bc7f576336b8f4d7eb5ba12/junit-4.13.2.jar
89+
// jar2: /home/ubuntu/.gradle/wrapper/dists/gradle-8.0-rc-1-all/2p8rgxxewg8l61n1p3vrzr9s8/gradle-8.0-rc-1/lib/junit-4.13.2.jar
90+
//
91+
task.getTestFrameworkProperty().convention(getProviderFactory().provider(() -> new JUnitTestFramework(task, task.getFilter(), false)));
92+
}
93+
}
8094
}
8195

8296
configure(allprojects - project(':distribution:archives:integ-test-zip')) {

buildSrc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ dependencies {
105105
api 'commons-codec:commons-codec:1.15'
106106
api 'org.apache.commons:commons-compress:1.22'
107107
api 'org.apache.ant:ant:1.10.13'
108-
api 'com.netflix.nebula:gradle-extra-configurations-plugin:8.0.0'
108+
api 'com.netflix.nebula:gradle-extra-configurations-plugin:9.0.0'
109109
api 'com.netflix.nebula:nebula-publishing-plugin:19.2.0'
110110
api 'com.netflix.nebula:gradle-info-plugin:12.0.0'
111111
api 'org.apache.rat:apache-rat:0.15'

buildSrc/src/main/java/org/opensearch/gradle/testclusters/StandaloneRestIntegTestTask.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.gradle.api.Task;
4040
import org.gradle.api.provider.Provider;
4141
import org.gradle.api.services.internal.BuildServiceRegistryInternal;
42+
import org.gradle.api.services.internal.BuildServiceProvider;
4243
import org.gradle.api.tasks.CacheableTask;
4344
import org.gradle.api.tasks.Internal;
4445
import org.gradle.api.tasks.Nested;
@@ -123,7 +124,7 @@ public List<ResourceLock> getSharedResources() {
123124
serviceRegistry,
124125
TestClustersPlugin.THROTTLE_SERVICE_NAME
125126
);
126-
SharedResource resource = serviceRegistry.forService(throttleProvider);
127+
final SharedResource resource = getSharedResource(serviceRegistry, throttleProvider);
127128

128129
int nodeCount = clusters.stream().mapToInt(cluster -> cluster.getNodes().size()).sum();
129130
if (nodeCount > 0) {
@@ -133,6 +134,37 @@ public List<ResourceLock> getSharedResources() {
133134
return Collections.unmodifiableList(locks);
134135
}
135136

137+
private SharedResource getSharedResource(
138+
BuildServiceRegistryInternal serviceRegistry,
139+
Provider<TestClustersThrottle> throttleProvider
140+
) {
141+
try {
142+
try {
143+
// The forService(Provider) is used by Gradle pre-8.0
144+
return (SharedResource) MethodHandles.publicLookup()
145+
.findVirtual(
146+
BuildServiceRegistryInternal.class,
147+
"forService",
148+
MethodType.methodType(SharedResource.class, Provider.class)
149+
)
150+
.bindTo(serviceRegistry)
151+
.invokeExact(throttleProvider);
152+
} catch (NoSuchMethodException | IllegalAccessException ex) {
153+
// The forService(BuildServiceProvider) is used by Gradle post-8.0
154+
return (SharedResource) MethodHandles.publicLookup()
155+
.findVirtual(
156+
BuildServiceRegistryInternal.class,
157+
"forService",
158+
MethodType.methodType(SharedResource.class, BuildServiceProvider.class)
159+
)
160+
.bindTo(serviceRegistry)
161+
.invokeExact((BuildServiceProvider<TestClustersThrottle, ?>) throttleProvider);
162+
}
163+
} catch (Throwable ex) {
164+
throw new IllegalStateException("Unable to find suitable BuildServiceRegistryInternal::forService", ex);
165+
}
166+
}
167+
136168
private ResourceLock getResourceLock(SharedResource resource, int nUsages) {
137169
try {
138170
try {

buildSrc/src/test/java/org/opensearch/gradle/JdkDownloadPluginTests.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
package org.opensearch.gradle;
3434

3535
import org.opensearch.gradle.test.GradleUnitTestCase;
36+
37+
import java.util.UUID;
38+
3639
import org.gradle.api.NamedDomainObjectContainer;
3740
import org.gradle.api.Project;
3841
import org.gradle.testfixtures.ProjectBuilder;
@@ -148,7 +151,8 @@ private void createJdk(Project project, String name, String vendor, String versi
148151
}
149152

150153
private Project createProject() {
151-
Project project = ProjectBuilder.builder().withParent(rootProject).build();
154+
final String name = UUID.randomUUID().toString();
155+
Project project = ProjectBuilder.builder().withName(name).withParent(rootProject).build();
152156
project.getPlugins().apply("opensearch.jdk-download");
153157
return project;
154158
}

buildSrc/src/test/java/org/opensearch/gradle/precommit/DependencyLicensesTaskTests.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.gradle.api.Action;
3636
import org.gradle.api.GradleException;
3737
import org.gradle.api.Project;
38+
import org.gradle.api.artifacts.Configuration;
3839
import org.gradle.api.artifacts.Dependency;
3940
import org.gradle.api.file.FileCollection;
4041
import org.gradle.api.plugins.JavaPlugin;
@@ -95,7 +96,7 @@ public void givenProjectWithoutLicensesDirButWithDependenciesThenShouldThrowExce
9596
expectedException.expect(GradleException.class);
9697
expectedException.expectMessage(containsString("does not exist, but there are dependencies"));
9798

98-
project.getDependencies().add("compileClasspath", dependency);
99+
project.getDependencies().add("someCompileConfiguration", dependency);
99100
task.get().checkDependencies();
100101
}
101102

@@ -113,7 +114,7 @@ public void givenProjectWithDependencyButNoShaFileThenShouldReturnException() th
113114
createFileIn(licensesDir, "groovy-LICENSE.txt", PERMISSIVE_LICENSE_TEXT);
114115
createFileIn(licensesDir, "groovy-NOTICE.txt", "");
115116

116-
project.getDependencies().add("compileClasspath", project.getDependencies().localGroovy());
117+
project.getDependencies().add("someCompileConfiguration", project.getDependencies().localGroovy());
117118
task.get().checkDependencies();
118119
}
119120

@@ -122,7 +123,7 @@ public void givenProjectWithDependencyButNoLicenseFileThenShouldReturnException(
122123
expectedException.expect(GradleException.class);
123124
expectedException.expectMessage(containsString("Missing LICENSE for "));
124125

125-
project.getDependencies().add("compileClasspath", project.getDependencies().localGroovy());
126+
project.getDependencies().add("someCompileConfiguration", project.getDependencies().localGroovy());
126127

127128
getLicensesDir(project).mkdir();
128129
updateShas.updateShas();
@@ -134,7 +135,7 @@ public void givenProjectWithDependencyButNoNoticeFileThenShouldReturnException()
134135
expectedException.expect(GradleException.class);
135136
expectedException.expectMessage(containsString("Missing NOTICE for "));
136137

137-
project.getDependencies().add("compileClasspath", dependency);
138+
project.getDependencies().add("someCompileConfiguration", dependency);
138139

139140
createFileIn(getLicensesDir(project), "groovy-LICENSE.txt", PERMISSIVE_LICENSE_TEXT);
140141

@@ -147,7 +148,7 @@ public void givenProjectWithStrictDependencyButNoSourcesFileThenShouldReturnExce
147148
expectedException.expect(GradleException.class);
148149
expectedException.expectMessage(containsString("Missing SOURCES for "));
149150

150-
project.getDependencies().add("compileClasspath", dependency);
151+
project.getDependencies().add("someCompileConfiguration", dependency);
151152

152153
createFileIn(getLicensesDir(project), "groovy-LICENSE.txt", STRICT_LICENSE_TEXT);
153154
createFileIn(getLicensesDir(project), "groovy-NOTICE.txt", "");
@@ -158,7 +159,7 @@ public void givenProjectWithStrictDependencyButNoSourcesFileThenShouldReturnExce
158159

159160
@Test
160161
public void givenProjectWithStrictDependencyAndEverythingInOrderThenShouldReturnSilently() throws Exception {
161-
project.getDependencies().add("compileClasspath", dependency);
162+
project.getDependencies().add("someCompileConfiguration", dependency);
162163

163164
createFileIn(getLicensesDir(project), "groovy-LICENSE.txt", STRICT_LICENSE_TEXT);
164165
createFileIn(getLicensesDir(project), "groovy-NOTICE.txt", "");
@@ -174,7 +175,7 @@ public void givenProjectWithStrictDependencyAndEverythingInOrderThenShouldReturn
174175

175176
@Test
176177
public void givenProjectWithDependencyAndEverythingInOrderThenShouldReturnSilently() throws Exception {
177-
project.getDependencies().add("compileClasspath", dependency);
178+
project.getDependencies().add("someCompileConfiguration", dependency);
178179

179180
File licensesDir = getLicensesDir(project);
180181

@@ -187,7 +188,7 @@ public void givenProjectWithALicenseButWithoutTheDependencyThenShouldThrowExcept
187188
expectedException.expect(GradleException.class);
188189
expectedException.expectMessage(containsString("Unused license "));
189190

190-
project.getDependencies().add("compileClasspath", dependency);
191+
project.getDependencies().add("someCompileConfiguration", dependency);
191192

192193
File licensesDir = getLicensesDir(project);
193194
createAllDefaultDependencyFiles(licensesDir, "groovy", "javaparser-core");
@@ -201,7 +202,7 @@ public void givenProjectWithANoticeButWithoutTheDependencyThenShouldThrowExcepti
201202
expectedException.expect(GradleException.class);
202203
expectedException.expectMessage(containsString("Unused notice "));
203204

204-
project.getDependencies().add("compileClasspath", dependency);
205+
project.getDependencies().add("someCompileConfiguration", dependency);
205206

206207
File licensesDir = getLicensesDir(project);
207208
createAllDefaultDependencyFiles(licensesDir, "groovy", "javaparser-core");
@@ -215,7 +216,7 @@ public void givenProjectWithAShaButWithoutTheDependencyThenShouldThrowException(
215216
expectedException.expect(GradleException.class);
216217
expectedException.expectMessage(containsString("Unused sha files found: \n"));
217218

218-
project.getDependencies().add("compileClasspath", dependency);
219+
project.getDependencies().add("someCompileConfiguration", dependency);
219220

220221
File licensesDir = getLicensesDir(project);
221222
createAllDefaultDependencyFiles(licensesDir, "groovy", "javaparser-core");
@@ -229,7 +230,7 @@ public void givenProjectWithADependencyWithWrongShaThenShouldThrowException() th
229230
expectedException.expect(GradleException.class);
230231
expectedException.expectMessage(containsString("SHA has changed! Expected "));
231232

232-
project.getDependencies().add("compileClasspath", dependency);
233+
project.getDependencies().add("someCompileConfiguration", dependency);
233234

234235
File licensesDir = getLicensesDir(project);
235236
createAllDefaultDependencyFiles(licensesDir, "groovy");
@@ -243,7 +244,7 @@ public void givenProjectWithADependencyWithWrongShaThenShouldThrowException() th
243244

244245
@Test
245246
public void givenProjectWithADependencyMappingThenShouldReturnSilently() throws Exception {
246-
project.getDependencies().add("compileClasspath", dependency);
247+
project.getDependencies().add("someCompileConfiguration", dependency);
247248

248249
File licensesDir = getLicensesDir(project);
249250
createAllDefaultDependencyFiles(licensesDir, "groovy", "javaparser");
@@ -258,7 +259,7 @@ public void givenProjectWithADependencyMappingThenShouldReturnSilently() throws
258259

259260
@Test
260261
public void givenProjectWithAIgnoreShaConfigurationAndNoShaFileThenShouldReturnSilently() throws Exception {
261-
project.getDependencies().add("compileClasspath", dependency);
262+
project.getDependencies().add("someCompileConfiguration", dependency);
262263

263264
File licensesDir = getLicensesDir(project);
264265
createFileIn(licensesDir, "groovy-LICENSE.txt", PERMISSIVE_LICENSE_TEXT);
@@ -297,6 +298,11 @@ private Project createProject() {
297298
Project project = ProjectBuilder.builder().build();
298299
project.getPlugins().apply(JavaPlugin.class);
299300

301+
Configuration compileClasspath = project.getConfigurations().getByName("compileClasspath");
302+
Configuration someCompileConfiguration = project.getConfigurations().create("someCompileConfiguration");
303+
// Declare a configuration that is going to resolve the compile classpath of the application
304+
project.getConfigurations().add(compileClasspath.extendsFrom(someCompileConfiguration));
305+
300306
return project;
301307
}
302308

buildSrc/src/test/java/org/opensearch/gradle/precommit/UpdateShasTaskTests.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.gradle.api.Action;
3737
import org.gradle.api.GradleException;
3838
import org.gradle.api.Project;
39+
import org.gradle.api.artifacts.Configuration;
3940
import org.gradle.api.artifacts.Dependency;
4041
import org.gradle.api.file.FileCollection;
4142
import org.gradle.api.plugins.JavaPlugin;
@@ -86,7 +87,7 @@ public void whenDependencyDoesntExistThenShouldDeleteDependencySha() throws IOEx
8687

8788
@Test
8889
public void whenDependencyExistsButShaNotThenShouldCreateNewShaFile() throws IOException, NoSuchAlgorithmException {
89-
project.getDependencies().add("compileClasspath", dependency);
90+
project.getDependencies().add("someCompileConfiguration", dependency);
9091

9192
getLicensesDir(project).mkdir();
9293
task.updateShas();
@@ -99,7 +100,7 @@ public void whenDependencyExistsButShaNotThenShouldCreateNewShaFile() throws IOE
99100

100101
@Test
101102
public void whenDependencyAndWrongShaExistsThenShouldNotOverwriteShaFile() throws IOException, NoSuchAlgorithmException {
102-
project.getDependencies().add("compileClasspath", dependency);
103+
project.getDependencies().add("someCompileConfiguration", dependency);
103104

104105
File groovyJar = task.getParentTask().getDependencies().getFiles().iterator().next();
105106
String groovyShaName = groovyJar.getName() + ".sha1";
@@ -122,6 +123,11 @@ private Project createProject() {
122123
Project project = ProjectBuilder.builder().build();
123124
project.getPlugins().apply(JavaPlugin.class);
124125

126+
Configuration compileClasspath = project.getConfigurations().getByName("compileClasspath");
127+
Configuration someCompileConfiguration = project.getConfigurations().create("someCompileConfiguration");
128+
// Declare a configuration that is going to resolve the compile classpath of the application
129+
project.getConfigurations().add(compileClasspath.extendsFrom(someCompileConfiguration));
130+
125131
return project;
126132
}
127133

buildSrc/src/testKit/thirdPartyAudit/sample_jars/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies {
4141
["0.0.1"].forEach { v ->
4242
["opensearch", "other"].forEach { p ->
4343
tasks.register("broken-log4j-${p}-${v}", Jar) {
44-
destinationDir = file("${buildDir}/testrepo/org/${p}/gradle/broken-log4j/${v}/")
44+
destinationDirectory = file("${buildDir}/testrepo/org/${p}/gradle/broken-log4j/${v}/")
4545
archiveFileName = "broken-log4j-${v}.jar"
4646
from sourceSets.main.output
4747
include "**/TestingLog4j.class"
@@ -51,7 +51,7 @@ dependencies {
5151
}
5252

5353
tasks.register("jarhellJdk", Jar) {
54-
destinationDir = file("${buildDir}/testrepo/org/other/gradle/jarhellJdk/0.0.1/")
54+
destinationDirectory = file("${buildDir}/testrepo/org/other/gradle/jarhellJdk/0.0.1/")
5555
archiveFileName = "jarhellJdk-0.0.1.jar"
5656
from sourceSets.main.output
5757
include "**/String.class"

buildSrc/version.properties

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spatial4j = 0.7
1010
jts = 1.15.0
1111
jackson = 2.14.2
1212
jackson_databind = 2.14.2
13-
snakeyaml = 1.32
13+
snakeyaml = 1.33
1414
icu4j = 70.1
1515
supercsv = 2.4.0
1616
# Update to 2.17.2+ is breaking OpenSearchJsonLayout (see https://issues.apache.org/jira/browse/LOG4J2-3562)
@@ -21,7 +21,8 @@ jettison = 1.5.3
2121
woodstox = 6.4.0
2222
kotlin = 1.7.10
2323
antlr4 = 4.11.1
24-
24+
guava = 31.1-jre
25+
2526
# when updating the JNA version, also update the version in buildSrc/build.gradle
2627
jna = 5.5.0
2728

distribution/packages/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import java.util.regex.Pattern
6363
*/
6464

6565
plugins {
66-
id "nebula.ospackage-base" version "9.1.1"
66+
id "com.netflix.nebula.ospackage-base" version "11.0.0"
6767
}
6868

6969
void addProcessFilesTask(String type, boolean jdk) {
@@ -290,7 +290,7 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
290290
}
291291
}
292292

293-
apply plugin: 'nebula.ospackage-base'
293+
apply plugin: 'com.netflix.nebula.ospackage-base'
294294

295295
// this is package indepdendent configuration
296296
ospackage {

gradle/wrapper/gradle-wrapper.jar

2.02 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
distributionBase=GRADLE_USER_HOME
1313
distributionPath=wrapper/dists
14-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
14+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
1515
zipStoreBase=GRADLE_USER_HOME
1616
zipStorePath=wrapper/dists
17-
distributionSha256Sum=312eb12875e1747e05c2f81a4789902d7e4ec5defbd1eefeaccc08acf096505d
17+
distributionSha256Sum=f30b29580fe11719087d698da23f3b0f0d04031d8995f7dd8275a31f7674dc01

0 commit comments

Comments
 (0)