Skip to content

Commit 5acc8cc

Browse files
authored
[8.17] Fix reproducability of builds against Java EA versions (#132847) (#132979)
* Fix reproducability of builds against Java EA versions (#132847) * Introduce dedicated toolchain resolver for EA java versions * Fix reproducability of builds against Java EA versions This fixes a reproducability issue when using the gradle javaToolChain api. There is no way to test toolchain candidates reliable against the build number in use. This meant that ones you e.g. have resolved some version of java 25, gradle toolchain detection does not detect the difference between certain builds (or even ea vs. released version) Therefore we fallback to rely on our custom JDKDownloadPlugin for now here. Syncing with the gradle team, they want to fix this somewhen in 9.x. We will revisit our solution ones something is available. Ultimately we want to get rid of usages of the JDK download plugin. * Minor cleanup and fixing non set distribution type in jdk * Fix ea jdk selection not just based on major version explicitly requires to add a ea postfix to the runtime sys property * Fix test reproduce linies when using java ea version * Apply review feedback * Use runtime jdk when patching * More cleanup (cherry picked from commit 16fe7db) # Conflicts: # BUILDING.md # build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy # build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/toolchain/OracleOpenJdkToolchainResolver.java # build-tools-internal/src/test/groovy/org/elasticsearch/gradle/internal/toolchain/OracleOpenJdkToolchainResolverSpec.groovy # test/framework/src/main/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java * Fix merge issues
1 parent 24ebfcb commit 5acc8cc

File tree

21 files changed

+457
-152
lines changed

21 files changed

+457
-152
lines changed

BUILDING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ uses the changed dependencies. In most cases, `precommit` or `check` are good ca
9292
We prefer sha256 checksums as md5 and sha1 are not considered safe anymore these days. The generated entry
9393
will have the `origin` attribute been set to `Generated by Gradle`.
9494

95+
<<<<<<< HEAD
9596
>A manual confirmation of the Gradle generated checksums is currently not mandatory.
9697
>If you want to add a level of verification you can manually confirm the checksum (e.g. by looking it up on the website of the library)
9798
>Please replace the content of the `origin` attribute by `official site` in that case.
9899
>
100+
=======
101+
> [!Tip]
102+
> A manual confirmation of the Gradle generated checksums is currently not mandatory.
103+
> If you want to add a level of verification you can manually confirm the checksum (e.g. by looking it up on the website of the library)
104+
> Please replace the content of the `origin` attribute by `official site` in that case.
105+
>>>>>>> 16fe7db13720 (Fix reproducability of builds against Java EA versions (#132847))
99106
100107
#### Custom plugin and task implementations
101108

@@ -186,6 +193,25 @@ dependencies {
186193

187194
To test an unreleased development version of a third party dependency you have several options.
188195

196+
### How do I test against java early access (ea) versions?
197+
198+
Currently only openjdk EA builds by oracle are supported.
199+
To test against an early access version java version you can pass the major
200+
java version appended with `-ea` as a system property (e.g. -Druntime.java=26-ea) to the Gradle build:
201+
202+
```
203+
./gradlew clean test -Druntime.java=26-ea
204+
```
205+
206+
This will run the tests using the JDK 26 EA version and pick the latest available build of the matching JDK EA version we expose
207+
in our custom jdk catalogue at `https://storage.googleapis.com/elasticsearch-jdk-archive/jdks/openjdk/latest.json`.
208+
209+
To run against a specific build number of the EA build you can pass a second system property (e.g. `-Druntime.java.build=6`):
210+
211+
```
212+
./gradlew clean test -Druntime.java=26-ea -Druntime.java.build=6
213+
```
214+
189215
#### How to use a Maven based third party dependency via `mavenlocal`?
190216

191217
1. Clone the third party repository locally
@@ -229,11 +255,16 @@ In addition to snapshot builds JitPack supports building Pull Requests. Simply u
229255
3. Run the Gradle build as needed. Keep in mind the initial resolution might take a bit longer as this needs to be built
230256
by JitPack in the background before we can resolve the adhoc built dependency.
231257

258+
<<<<<<< HEAD
232259
---
233260

234261
**NOTE**
235262

236263
You should only use that approach locally or on a developer branch for production dependencies as we do
264+
=======
265+
> [!Note]
266+
> You should only use that approach locally or on a developer branch for production dependencies as we do
267+
>>>>>>> 16fe7db13720 (Fix reproducability of builds against Java EA versions (#132847))
237268
not want to ship unreleased libraries into our releases.
238269
---
239270

@@ -265,10 +296,15 @@ allprojects {
265296
```
266297
4. Run the Gradle build as needed with `--write-verification-metadata` to ensure the Gradle dependency verification does not fail on your custom dependency.
267298

299+
<<<<<<< HEAD
268300
---
269301
**NOTE**
270302

271303
As Gradle prefers to use modules whose descriptor has been created from real meta-data rather than being generated,
304+
=======
305+
> [!Note]
306+
> As Gradle prefers to use modules whose descriptor has been created from real meta-data rather than being generated,
307+
>>>>>>> 16fe7db13720 (Fix reproducability of builds against Java EA versions (#132847))
272308
flat directory repositories cannot be used to override artifacts with real meta-data from other repositories declared in the build.
273309
For example, if Gradle finds only `jmxri-1.2.1.jar` in a flat directory repository, but `jmxri-1.2.1.pom` in another repository
274310
that supports meta-data, it will use the second repository to provide the module.

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractGitAwareGradleFuncTest.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.gradle.fixtures
1111

1212
import org.apache.commons.io.FileUtils
13-
import org.elasticsearch.gradle.internal.test.InternalAwareGradleRunner
1413
import org.gradle.testkit.runner.GradleRunner
1514
import org.junit.Rule
1615
import org.junit.rules.TemporaryFolder

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,29 @@ import java.util.regex.Pattern
2626

2727
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_ADOPTIUM
2828
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_OPENJDK
29+
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_OPENJDK
30+
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_ZULU
2931

3032
class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
3133

3234
private static final String OPENJDK_VERSION_OLD = "1+99"
3335
private static final String ADOPT_JDK_VERSION = "12.0.2+10"
3436
private static final String ADOPT_JDK_VERSION_11 = "11.0.10+9"
3537
private static final String ADOPT_JDK_VERSION_15 = "15.0.2+7"
38+
private static final String AZUL_JDK_VERSION_8 = "8u302+b08"
39+
private static final String AZUL_8_DISTRO_VERSION = "8.56.0.23"
40+
private static final String CATALOG_EA_VERSION = "25-ea+30"
3641
private static final String OPEN_JDK_VERSION = "12.0.1+99@123456789123456789123456789abcde"
3742
private static final Pattern JDK_HOME_LOGLINE = Pattern.compile("JDK HOME: (.*)")
3843

3944
def setup() {
40-
configurationCacheCompatible = false
45+
configurationCacheCompatible = false // JDK class references configurations which break configuration cache
4146
}
4247

4348
@Unroll
44-
def "jdk #jdkVendor for #platform#suffix are downloaded and extracted"() {
49+
def "jdk #distributionVersion #jdkVendor for #platform#suffix are downloaded and extracted"() {
4550
given:
46-
def mockRepoUrl = urlPath(jdkVendor, jdkVersion, platform, arch);
51+
def mockRepoUrl = urlPath(jdkVendor, jdkVersion, platform, arch, distributionVersion);
4752
def mockedContent = filebytes(jdkVendor, platform)
4853
buildFile.text = """
4954
plugins {
@@ -56,6 +61,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
5661
version = '$jdkVersion'
5762
platform = "$platform"
5863
architecture = '$arch'
64+
distributionVersion = '$distributionVersion'
5965
}
6066
}
6167
@@ -78,22 +84,27 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
7884
assertExtraction(result.output, expectedJavaBin);
7985

8086
where:
81-
platform | arch | jdkVendor | jdkVersion | expectedJavaBin | suffix
82-
"linux" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
83-
"linux" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "bin/java" | ""
84-
"linux" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "bin/java" | "(old version)"
85-
"windows" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
86-
"windows" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "bin/java" | ""
87-
"windows" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "bin/java" | "(old version)"
88-
"darwin" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "Contents/Home/bin/java" | ""
89-
"darwin" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "Contents/Home/bin/java" | ""
90-
"darwin" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "Contents/Home/bin/java" | "(old version)"
91-
"mac" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "Contents/Home/bin/java" | ""
92-
"mac" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "Contents/Home/bin/java" | "(old version)"
93-
"darwin" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "Contents/Home/bin/java" | ""
94-
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
95-
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_11 | "bin/java" | "(jdk 11)"
96-
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_15 | "bin/java" | "(jdk 15)"
87+
platform | arch | jdkVendor | jdkVersion | distributionVersion | expectedJavaBin | suffix
88+
"linux" | "aarch64" | VENDOR_OPENJDK | CATALOG_EA_VERSION | "ea" | "bin/java" | ""
89+
"linux" | "x64" | VENDOR_OPENJDK | CATALOG_EA_VERSION | "ea" | "bin/java" | ""
90+
"darwin" | "aarch64" | VENDOR_OPENJDK | CATALOG_EA_VERSION | "ea" | "Contents/Home/bin/java" | ""
91+
"darwin" | "x64" | VENDOR_OPENJDK | CATALOG_EA_VERSION | "ea" | "Contents/Home/bin/java" | ""
92+
"windows" | "x64" | VENDOR_OPENJDK | CATALOG_EA_VERSION | "ea" | "bin/java" | ""
93+
"linux" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "" | "bin/java" | ""
94+
"linux" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "" | "bin/java" | ""
95+
"linux" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "" | "bin/java" | "(old version)"
96+
"windows" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "" | "bin/java" | ""
97+
"windows" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "" | "bin/java" | ""
98+
"windows" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "" | "bin/java" | "(old version)"
99+
"darwin" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "" | "Contents/Home/bin/java" | ""
100+
"darwin" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "" | "Contents/Home/bin/java" | ""
101+
"darwin" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "" | "Contents/Home/bin/java" | "(old version)"
102+
"mac" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "" | "Contents/Home/bin/java" | ""
103+
"mac" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "" | "Contents/Home/bin/java" | "(old version)"
104+
"darwin" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "" | "Contents/Home/bin/java" | ""
105+
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "" | "bin/java" | ""
106+
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_11 | "" | "bin/java" | "(jdk 11)"
107+
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_15 | "" | "bin/java" | "(jdk 15)"
97108
}
98109

99110
def "transforms are reused across projects"() {
@@ -211,13 +222,19 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
211222
private static String urlPath(final String vendor,
212223
final String version,
213224
final String platform,
214-
final String arch = 'x64') {
215-
if (vendor.equals(VENDOR_ADOPTIUM)) {
225+
final String arch = 'x64',
226+
final String distributedVersion = '') {
227+
final boolean isOld = version.equals(OPENJDK_VERSION_OLD)
228+
229+
if (distributedVersion.equals("ea")) {
230+
def effectivePlatform = isMac(platform) ? "macos" : platform;
231+
def fileExtension = platform.toLowerCase().equals("windows") ? "zip" : "tar.gz";
232+
return "/jdks/openjdk/25/openjdk-${version}/openjdk-${version}_$effectivePlatform-${arch}_bin.$fileExtension";
233+
} else if (vendor.equals(VENDOR_ADOPTIUM)) {
216234
final String module = isMac(platform) ? "mac" : platform;
217235
return "/jdk-" + version + "/" + module + "/${arch}/jdk/hotspot/normal/adoptium";
218236
} else if (vendor.equals(VENDOR_OPENJDK)) {
219237
final String effectivePlatform = isMac(platform) ? "macos" : platform;
220-
final boolean isOld = version.equals(OPENJDK_VERSION_OLD);
221238
final String versionPath = isOld ? "jdk1/99" : "jdk12.0.1/123456789123456789123456789abcde/99";
222239
final String filename = "openjdk-" + (isOld ? "1" : "12.0.1") + "_" + effectivePlatform + "-x64_bin." + extension(platform);
223240
return "/java/GA/" + versionPath + "/GPL/" + filename;

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/Jdk.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class Jdk implements Buildable, Iterable<File> {
3131
"(\\d+)(\\.\\d+\\.\\d+(?:\\.\\d+)?)?\\+(\\d+(?:\\.\\d+)?)(@([a-f0-9]{32}))?"
3232
);
3333
private static final Pattern LEGACY_VERSION_PATTERN = Pattern.compile("(\\d)(u\\d+)\\+(b\\d+?)(@([a-f0-9]{32}))?");
34+
private static final Pattern EA_VERSION_PATTERN = Pattern.compile("(\\d+)-ea\\+(\\d+)(@([a-f0-9]{32}))?");
3435

3536
private final String name;
3637
private final Configuration configuration;
@@ -75,7 +76,9 @@ public String getVersion() {
7576
}
7677

7778
public void setVersion(String version) {
78-
if (VERSION_PATTERN.matcher(version).matches() == false && LEGACY_VERSION_PATTERN.matcher(version).matches() == false) {
79+
if (VERSION_PATTERN.matcher(version).matches() == false
80+
&& LEGACY_VERSION_PATTERN.matcher(version).matches() == false
81+
&& EA_VERSION_PATTERN.matcher(version).matches() == false) {
7982
throw new IllegalArgumentException("malformed version [" + version + "] for jdk [" + name + "]");
8083
}
8184
parseVersion(version);
@@ -109,7 +112,7 @@ public void setArchitecture(final String architecture) {
109112
}
110113

111114
public String getDistributionVersion() {
112-
return distributionVersion.get();
115+
return distributionVersion.getOrNull();
113116
}
114117

115118
public void setDistributionVersion(String distributionVersion) {
@@ -215,9 +218,17 @@ private void parseVersion(String version) {
215218
if (jdkVersionMatcher.matches() == false) {
216219
// Try again with the pre-Java9 version format
217220
jdkVersionMatcher = LEGACY_VERSION_PATTERN.matcher(version);
218-
219221
if (jdkVersionMatcher.matches() == false) {
220-
throw new IllegalArgumentException("Malformed jdk version [" + version + "]");
222+
// Try again with the pre-Java9 version format
223+
jdkVersionMatcher = EA_VERSION_PATTERN.matcher(version);
224+
if (jdkVersionMatcher.matches() == false) {
225+
throw new IllegalArgumentException("Malformed jdk version [" + version + "]");
226+
}
227+
baseVersion = version;
228+
major = jdkVersionMatcher.group(1);
229+
build = jdkVersionMatcher.group(2);
230+
hash = null;
231+
return;
221232
}
222233
}
223234

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/JdkDownloadPlugin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ private void setupRepository(Project project, Jdk jdk) {
115115
+ jdk.getBuild()
116116
+ "/[module]/[classifier]/jdk/hotspot/normal/adoptium";
117117
}
118+
} else if (jdk.getVendor().equals(VENDOR_OPENJDK) && "ea".equals(jdk.getDistributionVersion())) {
119+
repoUrl = "https://builds.es-jdk-archive.com/";
120+
// current pattern since 12.0.1
121+
artifactPattern = "jdks/openjdk/"
122+
+ jdk.getMajor()
123+
+ "/openjdk-"
124+
+ jdk.getBaseVersion()
125+
+ "/"
126+
+ "openjdk-[revision]_[module]-[classifier]_bin.[ext]";
118127
} else if (jdk.getVendor().equals(VENDOR_OPENJDK)) {
119128
repoUrl = "https://download.oracle.com";
120129
if (jdk.getHash() != null) {

0 commit comments

Comments
 (0)