Skip to content

Commit fec3b79

Browse files
authored
[build] Build with Microsoft OpenJDK 21.0.5 (#9683)
Context: #9651 Context: 14a6bfb Context: df68c20 As of 14a6bfb, main/.NET 10 supports both JDK 17 and 21. The default version that VS and the `InstallAndroidDependencies` target will install is currently JDK 17, though we may want to upgrade this to JDK 21 as we move further into the .NET 10 cycle. In order to increase our JDK test coverage across versions, the macOS, Windows, and Linux build stages have been updated to install and build with Microsoft OpenJDK 21.0.5. The nightly test jobs have also been updated to use JDK 21, while all other test jobs will continue to use JDK 17. JDK 11 support was removed in df68c20, though customers should be able to add: `<MinimumSupportedJavaVersion>11.0</MinimumSupportedJavaVersion>` to their project files to use it. Some test coverage for this exists in [ValidateJavaVersionTests][0], but this is not fully tested end to end. [0]: https://github.com/dotnet/android/blob/766ac338446f99129168dc02a16669882f6bd34e/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ValidateJavaVersionTests.cs
1 parent db357c7 commit fec3b79

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

build-tools/automation/azure-pipelines-nightly.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ stages:
123123
- template: /build-tools/automation/yaml-templates/setup-test-environment.yaml
124124
parameters:
125125
xaprepareScenario: EmulatorTestDependencies
126-
jdkMajorVersion: 11
126+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
127127

128128
- template: /build-tools/automation/yaml-templates/run-dotnet-preview.yaml
129129
parameters:
@@ -200,6 +200,7 @@ stages:
200200
installTestSlicer: true
201201
xaprepareScenario: EmulatorTestDependencies
202202
useAgentJdkPath: false
203+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
203204

204205
- task: DownloadPipelineArtifact@2
205206
inputs:
@@ -252,6 +253,7 @@ stages:
252253
installTestSlicer: true
253254
xaprepareScenario: EmulatorTestDependencies
254255
useAgentJdkPath: false
256+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
255257

256258
- task: DownloadPipelineArtifact@2
257259
inputs:

build-tools/automation/yaml-templates/build-linux.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ stages:
5252
# https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#checkout-path
5353
- checkout: maui
5454

55+
- template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml
56+
parameters:
57+
useAgentJdkPath: false
58+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
59+
5560
- template: /build-tools/automation/yaml-templates/use-dot-net.yaml
5661
parameters:
5762
remove_dotnet: true

build-tools/automation/yaml-templates/build-windows.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ stages:
4040
- template: /build-tools/automation/yaml-templates/clean.yaml
4141

4242
- template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml
43+
parameters:
44+
useAgentJdkPath: false
45+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
4346

4447
- template: /build-tools/automation/yaml-templates/use-dot-net.yaml
4548
parameters:

build-tools/automation/yaml-templates/commercial-build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ steps:
1111
- template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml
1212
parameters:
1313
useAgentJdkPath: false
14+
jdkMajorVersion: $(LatestJavaSdkMajorVersion)
1415

1516
- template: /build-tools/automation/yaml-templates/use-dot-net.yaml
1617
parameters:

build-tools/automation/yaml-templates/variables.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ variables:
6262
value: 35,Baklava
6363
- name: DefaultJavaSdkMajorVersion
6464
value: 17
65+
- name: LatestJavaSdkMajorVersion
66+
value: 21
6567
- name: ExcludedNightlyNUnitCategories
6668
value: 'cat != SystemApplication & cat != TimeZoneInfo & cat != Localization'
6769
- name: RunMAUITestJob

build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ partial class Configurables
1717
{
1818
const string BinutilsVersion = "L_18.1.6-8.0.0-1";
1919

20-
const string MicrosoftOpenJDK17Version = "17.0.12";
21-
const string MicrosoftOpenJDK17Release = "17.0.12";
22-
const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.12+7";
20+
const string MicrosoftOpenJDKVersion = "21.0.5";
21+
const string MicrosoftOpenJDKRelease = "21.0.5";
22+
const string MicrosoftOpenJDKRootDirName = "jdk-21.0.5+11";
2323

2424
static Context ctx => Context.Instance;
2525

@@ -28,7 +28,7 @@ public static partial class Urls
2828
// https://aka.ms/download-jdk/microsoft-jdk-17.0.11-linux-x64.tar.gz
2929
// https://aka.ms/download-jdk/microsoft-jdk-17.0.11-macOS-x64.tar.gz or https://aka.ms/download-jdk/microsoft-jdk-17.0.11-macos-aarch64.pkg
3030
// https://aka.ms/download-jdk/microsoft-jdk-17.0.11-windows-x64.zip
31-
public static readonly Uri MicrosoftOpenJDK17 = new Uri ($"https://aka.ms/download-jdk/microsoft-jdk-{MicrosoftOpenJDK17Version}-{MicrosoftOpenJDKOperatingSystem}.{MicrosoftOpenJDKFileExtension}");
31+
public static readonly Uri MicrosoftOpenJDK = new Uri ($"https://aka.ms/download-jdk/microsoft-jdk-{MicrosoftOpenJDKVersion}-{MicrosoftOpenJDKOperatingSystem}.{MicrosoftOpenJDKFileExtension}");
3232

3333
/// <summary>
3434
/// Base URL for all Android SDK and NDK downloads. Used in <see cref="AndroidToolchain"/>
@@ -43,11 +43,12 @@ public static partial class Defaults
4343
public static readonly string BinutilsVersion = Configurables.BinutilsVersion;
4444
public static readonly char[] PropertyListSeparator = new [] { ':' };
4545

46-
public static readonly string JdkFolder = "jdk-17";
46+
public static readonly string JdkFolder = "jdk-21";
4747

48-
public static readonly Version MicrosoftOpenJDK17Version = new Version (Configurables.MicrosoftOpenJDK17Version);
49-
public static readonly Version MicrosoftOpenJDK17Release = new Version (Configurables.MicrosoftOpenJDK17Release);
50-
public static readonly string MicrosoftOpenJDK17RootDirName = Configurables.MicrosoftOpenJDK17RootDirName;
48+
public static readonly Version MicrosoftMinOpenJDKVersion = new Version (17, 0);
49+
public static readonly Version MicrosoftOpenJDKVersion = new Version (Configurables.MicrosoftOpenJDKVersion);
50+
public static readonly Version MicrosoftOpenJDKRelease = new Version (Configurables.MicrosoftOpenJDKRelease);
51+
public static readonly string MicrosoftOpenJDKRootDirName = Configurables.MicrosoftOpenJDKRootDirName;
5152

5253
public const string DotNetTestRuntimeVersion = "3.1.11";
5354

@@ -187,9 +188,8 @@ public static partial class Paths
187188
public static string InstallMSBuildDir => GetCachedPath (ref installMSBuildDir, () => ctx.Properties.GetRequiredValue (KnownProperties.MicrosoftAndroidSdkOutDir));
188189

189190
// OpenJDK
190-
public static string OldOpenJDKInstallDir => GetCachedPath (ref oldOpenJDKInstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), "jdk-1.8"));
191-
public static string OpenJDK17InstallDir => GetCachedPath (ref openJDK17InstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), "jdk-17"));
192-
public static string OpenJDK17CacheDir => GetCachedPath (ref openJDK17CacheDir, () => ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory));
191+
public static string OpenJDKInstallDir => GetCachedPath (ref openJDKInstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), Defaults.JdkFolder));
192+
public static string OpenJDKCacheDir => GetCachedPath (ref openJDKCacheDir, () => ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory));
193193

194194
// .NET 6
195195
public static string NetcoreAppRuntimeAndroidARM => GetCachedPath (ref netcoreAppRuntimeAndroidARM, () => GetNetcoreAppRuntimePath (ctx, "arm"));
@@ -269,9 +269,8 @@ static string GetCachedPath (ref string? variable, Func<string> creator)
269269
static string? installMSBuildDir;
270270
static string? monoAndroidFrameworksRootDir;
271271
static string? externalJavaInteropDir;
272-
static string? openJDK17InstallDir;
273-
static string? openJDK17CacheDir;
274-
static string? oldOpenJDKInstallDir;
272+
static string? openJDKInstallDir;
273+
static string? openJDKCacheDir;
275274
static string? configurationPropsGeneratedPath;
276275
static string? windowsBinutilsInstallDir;
277276
static string? hostBinutilsInstallDir;

build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context)
156156
{ "@OS_RELEASE@", context.OS.Release ?? String.Empty },
157157
{ "@HOST_CPUS@", context.OS.CPUCount.ToString () },
158158
{ "@ARCHITECTURE_BITS@", context.OS.Is64Bit ? "64" : "32" },
159-
{ "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () },
159+
{ "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDKVersion.ToString () },
160160
{ "@JavaSdkDirectory@", context.OS.JavaHome },
161161
{ "@javac@", context.OS.JavaCPath },
162162
{ "@java@", context.OS.JavaPath },
163163
{ "@jar@", context.OS.JarPath },
164164
{ "@NDK_LLVM_TAG@", $"{context.OS.Type.ToLowerInvariant ()}-x86_64" },
165-
{ "@MIN_SUPPORTED_JDK_VERSION@", $"{Configurables.Defaults.MicrosoftOpenJDK17Version.Major}.0" },
165+
{ "@MIN_SUPPORTED_JDK_VERSION@", $"{Configurables.Defaults.MicrosoftMinOpenJDKVersion.Major}.0" },
166166
};
167167

168168
return new GeneratedPlaceholdersFile (

build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ public Step_InstallOpenJDK (string description, bool allowJIJavaHomeMatch = fals
4444

4545
protected override async Task<bool> Execute (Context context)
4646
{
47-
if (Directory.Exists (Configurables.Paths.OldOpenJDKInstallDir)) {
48-
Log.DebugLine ($"Found old OpenJDK directory at {Configurables.Paths.OldOpenJDKInstallDir}, removing");
49-
Utilities.DeleteDirectorySilent (Configurables.Paths.OldOpenJDKInstallDir);
50-
}
51-
5247
AddToInventory ();
5348

5449
string jdkInstallDir = JdkInstallDir;
@@ -291,11 +286,11 @@ public Step_InstallMicrosoftOpenJDK (bool allowJIJavaHomeMatch = false)
291286
}
292287

293288
protected override string ProductName => _ProductName;
294-
protected override string JdkInstallDir => Configurables.Paths.OpenJDK17InstallDir;
295-
protected override Version JdkVersion => Configurables.Defaults.MicrosoftOpenJDK17Version;
296-
protected override Version JdkRelease => Configurables.Defaults.MicrosoftOpenJDK17Release;
297-
protected override Uri JdkUrl => Configurables.Urls.MicrosoftOpenJDK17;
298-
protected override string JdkCacheDir => Configurables.Paths.OpenJDK17CacheDir;
299-
protected override string RootDirName => Configurables.Defaults.MicrosoftOpenJDK17RootDirName;
289+
protected override string JdkInstallDir => Configurables.Paths.OpenJDKInstallDir;
290+
protected override Version JdkVersion => Configurables.Defaults.MicrosoftOpenJDKVersion;
291+
protected override Version JdkRelease => Configurables.Defaults.MicrosoftOpenJDKRelease;
292+
protected override Uri JdkUrl => Configurables.Urls.MicrosoftOpenJDK;
293+
protected override string JdkCacheDir => Configurables.Paths.OpenJDKCacheDir;
294+
protected override string RootDirName => Configurables.Defaults.MicrosoftOpenJDKRootDirName;
300295
}
301296
}

0 commit comments

Comments
 (0)