Skip to content

Commit 162a31c

Browse files
authored
Merge pull request #1978 from gradle/gk/gradle9
Upgraded to Gradle 9 in samples and fixed the failures
2 parents cd3d4af + cf6a127 commit 162a31c

File tree

15 files changed

+54
-17
lines changed

15 files changed

+54
-17
lines changed

.github/workflows/convention-develocity-gradle-plugin-verification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
steps:
7373
- name: Checkout
7474
uses: actions/checkout@v4
75-
- name: Set up JDK 8
75+
- name: Set up JDK
7676
uses: actions/setup-java@v4
7777
with:
7878
java-version: ${{ matrix.versions.java }}

.github/workflows/convention-develocity-shared-verification.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,24 @@ jobs:
5858
- sample: '6.9_and_later'
5959
version: '8.0.2'
6060
java: '17'
61+
- sample: '6.9_and_later'
62+
version: '9.0.0'
63+
java: '21'
6164
- sample: '6.9_and_later'
6265
version: '(Current)'
6366
java: '21'
6467
steps:
6568
- name: Checkout
6669
uses: actions/checkout@v4
67-
- name: Set up JDK 8
70+
- name: Set up JDK
6871
uses: actions/setup-java@v4
6972
with:
7073
java-version: ${{ matrix.versions.java }}
7174
distribution: 'temurin'
7275
- name: Set up Gradle
7376
uses: gradle/actions/setup-gradle@v4
77+
with:
78+
gradle-version: ${{ matrix.versions.version != '(Current)' && matrix.versions.version || 'wrapper' }}
7479
- name: Download plugin
7580
uses: actions/download-artifact@v4
7681
with:
@@ -81,8 +86,8 @@ jobs:
8186
working-directory: convention-develocity-shared/examples/gradle_${{ matrix.versions.sample }}
8287
run: |
8388
sed -i '/distributionSha256Sum.*/d' gradle/wrapper/gradle-wrapper.properties
84-
./gradlew wrapper --gradle-version=${{ matrix.versions.version }} --no-scan
85-
./gradlew wrapper --gradle-version=${{ matrix.versions.version }} --no-scan
89+
gradle wrapper --gradle-version=${{ matrix.versions.version }} --no-scan
90+
gradle wrapper --gradle-version=${{ matrix.versions.version }} --no-scan
8691
- name: Verify example build
8792
id: build
8893
working-directory: convention-develocity-shared/examples/gradle_${{ matrix.versions.sample }}

build-data-capturing-gradle-samples/capture-quality-check-issues/gradle-quality-check-issues.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* and adds these as custom values.
44
*/
55

6+
import groovy.xml.XmlSlurper;
7+
68
def develocityApi = project.extensions.findByName('develocity')
79
if (!develocityApi) {
810
return

build-data-capturing-gradle-samples/capture-quality-check-issues/gradle-quality-check-issues.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ project.extensions.configure<DevelocityConfiguration>() {
3737
val files = report.getProperty("file") as NodeChildren
3838
files.forEach { f ->
3939
val file = f as NodeChild
40-
val filePath = project.rootProject.relativePath(file.attributes()["name"])
40+
val filePath = project.rootProject.relativePath(file.attributes()["name"]!!)
4141
val checkErrors = file.getProperty("error") as NodeChildren
4242
checkErrors.forEach { e ->
4343
val error = e as NodeChild
1.65 KB
Binary file not shown.

convention-develocity-gradle-plugin/plugins/gradle-5-or-newer/gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3+
distributionSha256Sum=8fad3d78296ca518113f3d29016617c7f9367dc005f932bd9d93bf45ba46072b
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME

convention-develocity-gradle-plugin/plugins/gradle-5-or-newer/gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2021 the original authors.
4+
# Copyright © 2015 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

convention-develocity-gradle-plugin/plugins/gradle-5-or-newer/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.gradle.util.GradleVersion;
1515

1616
import javax.inject.Inject;
17+
import java.lang.reflect.Method;
1718
import java.util.Optional;
1819

1920
/**
@@ -97,7 +98,7 @@ private boolean isCi() {
9798
// versions in order to detect changes when configuration cache is enabled.
9899
private Optional<String> environmentVariable(String name) {
99100
if (isGradle65OrNewer() && !isGradle74OrNewer()) {
100-
@SuppressWarnings("deprecation") Provider<String> variable = providers.environmentVariable(name).forUseAtConfigurationTime();
101+
Provider<String> variable = forUseAtConfigurationTime(providers.environmentVariable(name));
101102
return Optional.ofNullable(variable.getOrNull());
102103
}
103104
return Optional.ofNullable(System.getenv(name));
@@ -119,4 +120,18 @@ private static boolean isGradle5OrNewer() {
119120
return GradleVersion.current().compareTo(GradleVersion.version("5.0")) >= 0;
120121
}
121122

123+
private static Provider<String> forUseAtConfigurationTime(Provider<String> provider) {
124+
if (isGradle65OrNewer() && !isGradle74OrNewer()) {
125+
try {
126+
// Use reflection to access the forUseAtConfigurationTime method as it was removed in Gradle 9.
127+
Method method = Provider.class.getMethod("forUseAtConfigurationTime");
128+
return (Provider<String>) method.invoke(provider);
129+
} catch (Exception e) {
130+
throw new RuntimeException("Failed to invoke forUseAtConfigurationTime via reflection", e);
131+
}
132+
} else {
133+
return provider;
134+
}
135+
}
136+
122137
}

convention-develocity-shared/convention-develocity-gradle-plugin/src/main/java/com/myorg/configurable/GradleExecutionContext.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.gradle.api.provider.ProviderFactory;
55
import org.gradle.util.GradleVersion;
66

7+
import java.lang.reflect.Method;
78
import java.util.Optional;
89

910
public final class GradleExecutionContext implements ExecutionContext {
@@ -19,7 +20,7 @@ public GradleExecutionContext(ProviderFactory providers) {
1920
@Override
2021
public Optional<String> environmentVariable(String name) {
2122
if (isGradle65OrNewer() && !isGradle74OrNewer()) {
22-
@SuppressWarnings("deprecation") Provider<String> variable = providers.environmentVariable(name).forUseAtConfigurationTime();
23+
Provider<String> variable = forUseAtConfigurationTime(providers.environmentVariable(name));
2324
return Optional.ofNullable(variable.getOrNull());
2425
}
2526
return Optional.ofNullable(System.getenv(name));
@@ -30,7 +31,7 @@ public Optional<String> environmentVariable(String name) {
3031
@Override
3132
public Optional<String> systemProperty(String name) {
3233
if (isGradle65OrNewer() && !isGradle74OrNewer()) {
33-
@SuppressWarnings("deprecation") Provider<String> property = providers.systemProperty(name).forUseAtConfigurationTime();
34+
Provider<String> property = forUseAtConfigurationTime(providers.systemProperty(name));
3435
return Optional.ofNullable(property.getOrNull());
3536
}
3637
return Optional.ofNullable(System.getProperty(name));
@@ -45,4 +46,18 @@ private static boolean isGradle74OrNewer() {
4546
return GradleVersion.current().compareTo(GradleVersion.version("7.4")) >= 0;
4647
}
4748

49+
private static Provider<String> forUseAtConfigurationTime(Provider<String> provider) {
50+
if (isGradle65OrNewer() && !isGradle74OrNewer()) {
51+
try {
52+
// Use reflection to access the forUseAtConfigurationTime method as it was removed in Gradle 9.
53+
Method method = Provider.class.getMethod("forUseAtConfigurationTime");
54+
return (Provider<String>) method.invoke(provider);
55+
} catch (Exception e) {
56+
throw new RuntimeException("Failed to invoke forUseAtConfigurationTime via reflection", e);
57+
}
58+
} else {
59+
return provider;
60+
}
61+
}
62+
4863
}
1.65 KB
Binary file not shown.

0 commit comments

Comments
 (0)