Allow experimental Java target 21 by default
Bug: 342332820
Test: EXPERIMENTAL_TARGET_JAVA_VERSION_21=true m
Change-Id: I6cc21bf191385df91c2446b7cd6291a0e3532bea
diff --git a/android/config.go b/android/config.go
index 76c590a..6007451 100644
--- a/android/config.go
+++ b/android/config.go
@@ -827,6 +827,10 @@
return value == "0" || value == "n" || value == "no" || value == "off" || value == "false"
}
+func (c *config) TargetsJava21() bool {
+ return c.IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_21")
+}
+
// EnvDeps returns the environment variables this build depends on. The first
// call to this function blocks future reads from the environment.
func (c *config) EnvDeps() map[string]string {
diff --git a/java/java.go b/java/java.go
index fc7e5c5..3c16cc7 100644
--- a/java/java.go
+++ b/java/java.go
@@ -577,6 +577,12 @@
return normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() {
return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
+ } else if ctx.Config().TargetsJava21() {
+ // Temporary experimental flag to be able to try and build with
+ // java version 21 options. The flag, if used, just sets Java
+ // 21 as the default version, leaving any components that
+ // target an older version intact.
+ return JAVA_VERSION_21
} else {
return JAVA_VERSION_17
}
diff --git a/java/sdk.go b/java/sdk.go
index d972c19..4ef4ee2 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -65,6 +65,12 @@
return JAVA_VERSION_9
} else if sdk.FinalOrFutureInt() <= 33 {
return JAVA_VERSION_11
+ } else if ctx.Config().TargetsJava21() {
+ // Temporary experimental flag to be able to try and build with
+ // java version 21 options. The flag, if used, just sets Java
+ // 21 as the default version, leaving any components that
+ // target an older version intact.
+ return JAVA_VERSION_21
} else {
return JAVA_VERSION_17
}