Add CI build using JDK 21 (#2552)

* Add CI build using JDK 21

This is mainly to make sure that besides the known JDK 21 build
incompatibilities Gson can be built and run using JDK 21.

* Update ProGuard

* Update Protobuf

3.25.1 is actually newer than 4.0.0-rc-2
This commit is contained in:
Marcono1234 2023-11-27 01:36:43 +01:00 committed by GitHub
parent 6f1a18af52
commit 4197bb6545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 3 deletions

View File

@ -11,6 +11,12 @@ jobs:
strategy:
matrix:
java: [ 11, 17 ]
# Custom JDK 21 configuration
include:
- java: 21
# Disable Enforcer check which (intentionally) prevents using JDK 21 for building
# Exclude 'shrinker-test' module because R8 does not support JDK 21 yet
extra-mvn-args: -Denforcer.fail=false --projects '!:shrinker-test'
runs-on: ubuntu-latest
steps:
@ -23,7 +29,7 @@ jobs:
cache: 'maven'
- name: Build with Maven
# This also runs javadoc:jar to detect any issues with the Javadoc generated during release
run: mvn --batch-mode --no-transfer-progress verify javadoc:jar
run: mvn --batch-mode --no-transfer-progress verify javadoc:jar ${{ matrix.extra-mvn-args || '' }}
native-image-test:
name: "GraalVM Native Image test"

View File

@ -191,6 +191,19 @@
</goals>
</execution>
</executions>
<!-- Upgrades ProGuard to version newer than the one included by plugin by default -->
<dependencies>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-base</artifactId>
<version>7.4.1</version>
</dependency>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-core</artifactId>
<version>9.1.0</version>
</dependency>
</dependencies>
<configuration>
<obfuscate>true</obfuscate>
<injar>test-classes-obfuscated-injar</injar>

View File

@ -18,6 +18,7 @@ package com.google.gson.functional;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -52,6 +53,9 @@ public class ReflectionAccessTest {
@SuppressWarnings("removal") // java.lang.SecurityManager deprecation in Java 17
@Test
public void testRestrictiveSecurityManager() throws Exception {
// Skip for newer Java versions where `System.setSecurityManager` is unsupported
assumeTrue(Runtime.version().feature() <= 17);
// Must use separate class loader, otherwise permission is not checked, see
// Class.getDeclaredFields()
Class<?> clazz = loadClassWithDifferentClassLoader(ClassWithPrivateMembers.class);

14
pom.xml
View File

@ -463,6 +463,20 @@
</build>
</profile>
<!-- Slightly adjust build to support building with JDK >= 21
However, by default this will intentionally be blocked by the Maven Enforcer Plugin defined above
and must be explicitly circumvented to avoid building non-release Gson artifacts by accident -->
<profile>
<id>jdk21+</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<properties>
<!-- JDK 21 does not support Java 7 as release, must use at least Java 8 -->
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
<!-- Profile defining additional plugins to be executed for release -->
<profile>
<id>release</id>

View File

@ -31,6 +31,8 @@
<!-- Make the build reproducible, see root `pom.xml` -->
<!-- This is duplicated here because that is recommended by `artifact:check-buildplan` -->
<project.build.outputTimestamp>2023-01-01T00:00:00Z</project.build.outputTimestamp>
<protobufVersion>3.25.1</protobufVersion>
</properties>
<licenses>
@ -50,7 +52,7 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.0.0-rc-2</version>
<version>${protobufVersion}</version>
</dependency>
<dependency>
@ -89,7 +91,7 @@
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.3:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:${protobufVersion}:exe:${os.detected.classifier}</protocArtifact>
</configuration>
<executions>
<execution>

View File

@ -104,6 +104,19 @@
</goals>
</execution>
</executions>
<!-- Upgrades ProGuard to version newer than the one included by plugin by default -->
<dependencies>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-base</artifactId>
<version>7.4.1</version>
</dependency>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-core</artifactId>
<version>9.1.0</version>
</dependency>
</dependencies>
<configuration>
<obfuscate>true</obfuscate>
<proguardInclude>${project.basedir}/proguard.pro</proguardInclude>
@ -205,6 +218,7 @@
but it appears that can be ignored -->
<groupId>com.android.tools</groupId>
<artifactId>r8</artifactId>
<!-- TODO: When updating to a version which supports JDK 21, remove 'shrinker-test' exclusion from build.yml workflow -->
<version>8.1.72</version>
</dependency>
</dependencies>