Skip to content

Commit

Permalink
Merge branch 'main' into marcono1234/GsonBuilder-setDateFormat-DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 authored Dec 2, 2023
2 parents 8a3fd5c + 48a5344 commit ef65603
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Gson uses Maven to build the project:
mvn clean verify
```

JDK 11 or newer is required for building, JDK 17 is recommended.
JDK 11 or newer is required for building, JDK 17 is recommended. Newer JDKs are currently not supported for building (but are supported when _using_ Gson).

### Contributing

Expand Down
13 changes: 13 additions & 0 deletions gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.1</version>
</dependency>
</dependencies>
<configuration>
<obfuscate>true</obfuscate>
<injar>test-classes-obfuscated-injar</injar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.google.gson.internal;

/**
* Build configuration for Gson. This file is automatically populated by
* templating-maven-plugin and .java/.class files are generated for use in Gson.
* Build configuration for Gson. This file is automatically populated by templating-maven-plugin and
* .java/.class files are generated for use in Gson.
*
* @author Inderjeet Singh
*/
Expand All @@ -28,5 +28,5 @@ public final class GsonBuildConfig {
/** This field is automatically populated by Maven when a build is triggered */
public static final String VERSION = "${project.version}";

private GsonBuildConfig() { }
private GsonBuildConfig() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand Down Expand Up @@ -52,6 +53,9 @@ private static Class<?> loadClassWithDifferentClassLoader(Class<?> c) throws Exc
@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);
Expand Down
26 changes: 22 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
<!-- Enforce that correct JDK version is used to avoid cryptic build errors -->
<requireJavaVersion>
<!-- Other plugins of this build require at least JDK 11 -->
<version>[11,)</version>
<!-- Fail fast when building with JDK > 17 because it causes build failures,
see https://github.com/google/gson/issues/2501 -->
<version>[11,18)</version>
</requireJavaVersion>
</rules>
</configuration>
Expand All @@ -132,7 +134,7 @@
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
<version>2.41.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -166,11 +168,13 @@
</formats>

<java>
<!-- Exclude classes which need Java 17 for compilation; Google Java Format internally relies on javac,
so formatting will fail if build is executed with JDK 11 -->
<excludes>
<!-- Exclude classes which need Java 17 for compilation; Google Java Format internally relies on javac,
so formatting will fail if build is executed with JDK 11 -->
<exclude>src/test/java/com/google/gson/functional/Java17RecordTest.java</exclude>
<exclude>src/test/java/com/google/gson/native_test/Java17RecordReflectionTest.java</exclude>
<!-- Exclude protobuf generated code. -->
<exclude>target/generated-test-sources/protobuf/**/*.java</exclude>
</excludes>
<googleJavaFormat>
<style>GOOGLE</style>
Expand Down Expand Up @@ -461,6 +465,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>
Expand Down
6 changes: 4 additions & 2 deletions proto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
14 changes: 14 additions & 0 deletions shrinker-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.1</version>
</dependency>
</dependencies>
<configuration>
<obfuscate>true</obfuscate>
<proguardInclude>${project.basedir}/proguard.pro</proguardInclude>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit ef65603

Please sign in to comment.