From fec3b7943cd6a1b476592dae6201a4647221a552 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Thu, 16 Jan 2025 11:51:07 -0500 Subject: [PATCH] [build] Build with Microsoft OpenJDK 21.0.5 (#9683) Context: https://github.com/dotnet/android/pull/9651 Context: https://github.com/dotnet/android/commit/14a6bfb925c3f18c677507fe07bd171e559f458f Context: https://github.com/dotnet/android/commit/df68c208ad02d09ebb9e6a87053343985dfc1e36 As of https://github.com/dotnet/android/commit/14a6bfb925c3f18c677507fe07bd171e559f458f, 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 https://github.com/dotnet/android/commit/df68c208ad02d09ebb9e6a87053343985dfc1e36, though customers should be able to add: `11.0` 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 --- .../automation/azure-pipelines-nightly.yaml | 4 ++- .../yaml-templates/build-linux.yaml | 5 ++++ .../yaml-templates/build-windows.yaml | 3 +++ .../yaml-templates/commercial-build.yaml | 1 + .../automation/yaml-templates/variables.yaml | 2 ++ .../xaprepare/ConfigAndData/Configurables.cs | 27 +++++++++---------- .../xaprepare/Steps/Step_GenerateFiles.cs | 4 +-- .../Steps/Step_InstallAdoptOpenJDK.cs | 17 +++++------- 8 files changed, 35 insertions(+), 28 deletions(-) diff --git a/build-tools/automation/azure-pipelines-nightly.yaml b/build-tools/automation/azure-pipelines-nightly.yaml index 2fc23d55aff..01f5b01ae05 100644 --- a/build-tools/automation/azure-pipelines-nightly.yaml +++ b/build-tools/automation/azure-pipelines-nightly.yaml @@ -123,7 +123,7 @@ stages: - template: /build-tools/automation/yaml-templates/setup-test-environment.yaml parameters: xaprepareScenario: EmulatorTestDependencies - jdkMajorVersion: 11 + jdkMajorVersion: $(LatestJavaSdkMajorVersion) - template: /build-tools/automation/yaml-templates/run-dotnet-preview.yaml parameters: @@ -200,6 +200,7 @@ stages: installTestSlicer: true xaprepareScenario: EmulatorTestDependencies useAgentJdkPath: false + jdkMajorVersion: $(LatestJavaSdkMajorVersion) - task: DownloadPipelineArtifact@2 inputs: @@ -252,6 +253,7 @@ stages: installTestSlicer: true xaprepareScenario: EmulatorTestDependencies useAgentJdkPath: false + jdkMajorVersion: $(LatestJavaSdkMajorVersion) - task: DownloadPipelineArtifact@2 inputs: diff --git a/build-tools/automation/yaml-templates/build-linux.yaml b/build-tools/automation/yaml-templates/build-linux.yaml index 6e098e9bb40..260020fc832 100644 --- a/build-tools/automation/yaml-templates/build-linux.yaml +++ b/build-tools/automation/yaml-templates/build-linux.yaml @@ -52,6 +52,11 @@ stages: # https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#checkout-path - checkout: maui + - template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml + parameters: + useAgentJdkPath: false + jdkMajorVersion: $(LatestJavaSdkMajorVersion) + - template: /build-tools/automation/yaml-templates/use-dot-net.yaml parameters: remove_dotnet: true diff --git a/build-tools/automation/yaml-templates/build-windows.yaml b/build-tools/automation/yaml-templates/build-windows.yaml index 52c6e17838d..95db7e69485 100644 --- a/build-tools/automation/yaml-templates/build-windows.yaml +++ b/build-tools/automation/yaml-templates/build-windows.yaml @@ -40,6 +40,9 @@ stages: - template: /build-tools/automation/yaml-templates/clean.yaml - template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml + parameters: + useAgentJdkPath: false + jdkMajorVersion: $(LatestJavaSdkMajorVersion) - template: /build-tools/automation/yaml-templates/use-dot-net.yaml parameters: diff --git a/build-tools/automation/yaml-templates/commercial-build.yaml b/build-tools/automation/yaml-templates/commercial-build.yaml index 0e2ed655eee..93b4d1eb6f7 100644 --- a/build-tools/automation/yaml-templates/commercial-build.yaml +++ b/build-tools/automation/yaml-templates/commercial-build.yaml @@ -11,6 +11,7 @@ steps: - template: /build-tools/automation/yaml-templates/setup-jdk-variables.yaml parameters: useAgentJdkPath: false + jdkMajorVersion: $(LatestJavaSdkMajorVersion) - template: /build-tools/automation/yaml-templates/use-dot-net.yaml parameters: diff --git a/build-tools/automation/yaml-templates/variables.yaml b/build-tools/automation/yaml-templates/variables.yaml index d1abe276018..8ccf626412c 100644 --- a/build-tools/automation/yaml-templates/variables.yaml +++ b/build-tools/automation/yaml-templates/variables.yaml @@ -62,6 +62,8 @@ variables: value: 35,Baklava - name: DefaultJavaSdkMajorVersion value: 17 +- name: LatestJavaSdkMajorVersion + value: 21 - name: ExcludedNightlyNUnitCategories value: 'cat != SystemApplication & cat != TimeZoneInfo & cat != Localization' - name: RunMAUITestJob diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs index 103d07403fc..9c77341f969 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs @@ -17,9 +17,9 @@ partial class Configurables { const string BinutilsVersion = "L_18.1.6-8.0.0-1"; - const string MicrosoftOpenJDK17Version = "17.0.12"; - const string MicrosoftOpenJDK17Release = "17.0.12"; - const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.12+7"; + const string MicrosoftOpenJDKVersion = "21.0.5"; + const string MicrosoftOpenJDKRelease = "21.0.5"; + const string MicrosoftOpenJDKRootDirName = "jdk-21.0.5+11"; static Context ctx => Context.Instance; @@ -28,7 +28,7 @@ public static partial class Urls // https://aka.ms/download-jdk/microsoft-jdk-17.0.11-linux-x64.tar.gz // 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 // https://aka.ms/download-jdk/microsoft-jdk-17.0.11-windows-x64.zip - public static readonly Uri MicrosoftOpenJDK17 = new Uri ($"https://aka.ms/download-jdk/microsoft-jdk-{MicrosoftOpenJDK17Version}-{MicrosoftOpenJDKOperatingSystem}.{MicrosoftOpenJDKFileExtension}"); + public static readonly Uri MicrosoftOpenJDK = new Uri ($"https://aka.ms/download-jdk/microsoft-jdk-{MicrosoftOpenJDKVersion}-{MicrosoftOpenJDKOperatingSystem}.{MicrosoftOpenJDKFileExtension}"); /// /// Base URL for all Android SDK and NDK downloads. Used in @@ -43,11 +43,12 @@ public static partial class Defaults public static readonly string BinutilsVersion = Configurables.BinutilsVersion; public static readonly char[] PropertyListSeparator = new [] { ':' }; - public static readonly string JdkFolder = "jdk-17"; + public static readonly string JdkFolder = "jdk-21"; - public static readonly Version MicrosoftOpenJDK17Version = new Version (Configurables.MicrosoftOpenJDK17Version); - public static readonly Version MicrosoftOpenJDK17Release = new Version (Configurables.MicrosoftOpenJDK17Release); - public static readonly string MicrosoftOpenJDK17RootDirName = Configurables.MicrosoftOpenJDK17RootDirName; + public static readonly Version MicrosoftMinOpenJDKVersion = new Version (17, 0); + public static readonly Version MicrosoftOpenJDKVersion = new Version (Configurables.MicrosoftOpenJDKVersion); + public static readonly Version MicrosoftOpenJDKRelease = new Version (Configurables.MicrosoftOpenJDKRelease); + public static readonly string MicrosoftOpenJDKRootDirName = Configurables.MicrosoftOpenJDKRootDirName; public const string DotNetTestRuntimeVersion = "3.1.11"; @@ -187,9 +188,8 @@ public static partial class Paths public static string InstallMSBuildDir => GetCachedPath (ref installMSBuildDir, () => ctx.Properties.GetRequiredValue (KnownProperties.MicrosoftAndroidSdkOutDir)); // OpenJDK - public static string OldOpenJDKInstallDir => GetCachedPath (ref oldOpenJDKInstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), "jdk-1.8")); - public static string OpenJDK17InstallDir => GetCachedPath (ref openJDK17InstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), "jdk-17")); - public static string OpenJDK17CacheDir => GetCachedPath (ref openJDK17CacheDir, () => ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory)); + public static string OpenJDKInstallDir => GetCachedPath (ref openJDKInstallDir, () => Path.Combine (ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory), Defaults.JdkFolder)); + public static string OpenJDKCacheDir => GetCachedPath (ref openJDKCacheDir, () => ctx.Properties.GetRequiredValue (KnownProperties.AndroidToolchainCacheDirectory)); // .NET 6 public static string NetcoreAppRuntimeAndroidARM => GetCachedPath (ref netcoreAppRuntimeAndroidARM, () => GetNetcoreAppRuntimePath (ctx, "arm")); @@ -269,9 +269,8 @@ static string GetCachedPath (ref string? variable, Func creator) static string? installMSBuildDir; static string? monoAndroidFrameworksRootDir; static string? externalJavaInteropDir; - static string? openJDK17InstallDir; - static string? openJDK17CacheDir; - static string? oldOpenJDKInstallDir; + static string? openJDKInstallDir; + static string? openJDKCacheDir; static string? configurationPropsGeneratedPath; static string? windowsBinutilsInstallDir; static string? hostBinutilsInstallDir; diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs index 167c48515f1..af3c6cac1b6 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs @@ -156,13 +156,13 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context) { "@OS_RELEASE@", context.OS.Release ?? String.Empty }, { "@HOST_CPUS@", context.OS.CPUCount.ToString () }, { "@ARCHITECTURE_BITS@", context.OS.Is64Bit ? "64" : "32" }, - { "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () }, + { "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDKVersion.ToString () }, { "@JavaSdkDirectory@", context.OS.JavaHome }, { "@javac@", context.OS.JavaCPath }, { "@java@", context.OS.JavaPath }, { "@jar@", context.OS.JarPath }, { "@NDK_LLVM_TAG@", $"{context.OS.Type.ToLowerInvariant ()}-x86_64" }, - { "@MIN_SUPPORTED_JDK_VERSION@", $"{Configurables.Defaults.MicrosoftOpenJDK17Version.Major}.0" }, + { "@MIN_SUPPORTED_JDK_VERSION@", $"{Configurables.Defaults.MicrosoftMinOpenJDKVersion.Major}.0" }, }; return new GeneratedPlaceholdersFile ( diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs b/build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs index 2d3c9e5d99e..92cacaa7c1f 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs @@ -44,11 +44,6 @@ public Step_InstallOpenJDK (string description, bool allowJIJavaHomeMatch = fals protected override async Task Execute (Context context) { - if (Directory.Exists (Configurables.Paths.OldOpenJDKInstallDir)) { - Log.DebugLine ($"Found old OpenJDK directory at {Configurables.Paths.OldOpenJDKInstallDir}, removing"); - Utilities.DeleteDirectorySilent (Configurables.Paths.OldOpenJDKInstallDir); - } - AddToInventory (); string jdkInstallDir = JdkInstallDir; @@ -291,11 +286,11 @@ public Step_InstallMicrosoftOpenJDK (bool allowJIJavaHomeMatch = false) } protected override string ProductName => _ProductName; - protected override string JdkInstallDir => Configurables.Paths.OpenJDK17InstallDir; - protected override Version JdkVersion => Configurables.Defaults.MicrosoftOpenJDK17Version; - protected override Version JdkRelease => Configurables.Defaults.MicrosoftOpenJDK17Release; - protected override Uri JdkUrl => Configurables.Urls.MicrosoftOpenJDK17; - protected override string JdkCacheDir => Configurables.Paths.OpenJDK17CacheDir; - protected override string RootDirName => Configurables.Defaults.MicrosoftOpenJDK17RootDirName; + protected override string JdkInstallDir => Configurables.Paths.OpenJDKInstallDir; + protected override Version JdkVersion => Configurables.Defaults.MicrosoftOpenJDKVersion; + protected override Version JdkRelease => Configurables.Defaults.MicrosoftOpenJDKRelease; + protected override Uri JdkUrl => Configurables.Urls.MicrosoftOpenJDK; + protected override string JdkCacheDir => Configurables.Paths.OpenJDKCacheDir; + protected override string RootDirName => Configurables.Defaults.MicrosoftOpenJDKRootDirName; } }