Skip to content

Commit

Permalink
[build] Build with Microsoft OpenJDK 21.0.5 (#9683)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pjcollins authored Jan 16, 2025
1 parent db357c7 commit fec3b79
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
4 changes: 3 additions & 1 deletion build-tools/automation/azure-pipelines-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -200,6 +200,7 @@ stages:
installTestSlicer: true
xaprepareScenario: EmulatorTestDependencies
useAgentJdkPath: false
jdkMajorVersion: $(LatestJavaSdkMajorVersion)

- task: DownloadPipelineArtifact@2
inputs:
Expand Down Expand Up @@ -252,6 +253,7 @@ stages:
installTestSlicer: true
xaprepareScenario: EmulatorTestDependencies
useAgentJdkPath: false
jdkMajorVersion: $(LatestJavaSdkMajorVersion)

- task: DownloadPipelineArtifact@2
inputs:
Expand Down
5 changes: 5 additions & 0 deletions build-tools/automation/yaml-templates/build-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions build-tools/automation/yaml-templates/build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions build-tools/automation/yaml-templates/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 13 additions & 14 deletions build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}");

/// <summary>
/// Base URL for all Android SDK and NDK downloads. Used in <see cref="AndroidToolchain"/>
Expand All @@ -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";

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -269,9 +269,8 @@ static string GetCachedPath (ref string? variable, Func<string> 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;
Expand Down
4 changes: 2 additions & 2 deletions build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
17 changes: 6 additions & 11 deletions build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public Step_InstallOpenJDK (string description, bool allowJIJavaHomeMatch = fals

protected override async Task<bool> 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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit fec3b79

Please sign in to comment.