Skip to content

Commit

Permalink
Document minimum Android API level and add workflow to check compatib…
Browse files Browse the repository at this point in the history
…ility (#2431)
  • Loading branch information
Marcono1234 committed Jul 6, 2023
1 parent a589ef2 commit 6d9c356
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check-android-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# For security reasons this is a separate GitHub workflow, see https://github.com/google/gson/issues/2429#issuecomment-1622522842
# Once https://github.com/mojohaus/animal-sniffer/issues/252 or https://github.com/mojohaus/animal-sniffer/pull/253
# are resolved, can consider adjusting pom.xml to include this as part of normal Maven build

name: Check Android compatibility

on: [push, pull_request]

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
check-android-compatibility:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'

- name: Check Android compatibility
run: |
# Run 'test' phase because plugin normally expects to be executed after tests have been compiled
mvn --batch-mode --no-transfer-progress test animal-sniffer:check@check-android-compatibility -DskipTests
2 changes: 2 additions & 0 deletions .github/workflows/check-api-compatibility.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This workflow makes sure that a pull request does not make any incompatible changes
# to the public API of Gson
name: Check API compatibility

on: pull_request
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ When this module is present, Gson can use the `Unsafe` class to create instances
However, care should be taken when relying on this. `Unsafe` is not available in all environments and its usage has some pitfalls,
see [`GsonBuilder.disableJdkUnsafe()`](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/GsonBuilder.html#disableJdkUnsafe()).

#### Minimum Android API level

- Gson 2.11.0 and newer: API level 21
- Gson 2.10.1 and older: API level 19

Older Gson versions may also support lower API levels, however this has not been verified.

### Documentation
* [API Javadoc](https://www.javadoc.io/doc/com.google.code.gson/gson): Documentation for the current release
* [User guide](UserGuide.md): This guide contains examples on how to use Gson in your code
Expand Down
1 change: 1 addition & 0 deletions gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>JDK17</id>
Expand Down
8 changes: 8 additions & 0 deletions metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<!-- This module is not supposed to be consumed as library, so no need to check used classes -->
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,33 @@
</parameter>
</configuration>
</plugin>
<!-- Plugin for checking compatibility with Android API -->
<!-- Note: For now this is not part of a normal Maven build but instead executed only by a
GitHub workflow because the Animal Sniffer signature files use Java Serialization, so they
could in theory contain malicious data (in case we don't fully trust the author) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.23</version>
<executions>
<execution>
<id>check-android-compatibility</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<!-- Note: In case Android compatibility impedes Gson development too much in the
future, could consider switching to https://github.com/open-toast/gummy-bears
which accounts for Android desugaring and might allow usage of more Java classes -->
<groupId>net.sf.androidscents.signature</groupId>
<artifactId>android-api-level-21</artifactId>
<version>5.0.1_r2</version>
</signature>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
8 changes: 8 additions & 0 deletions shrinker-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<!-- This module is not supposed to be consumed as library, so no need to check used classes -->
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down

0 comments on commit 6d9c356

Please sign in to comment.