gson
Used in:
components
- OverviewOverview
- VersionsVersions
- DependentsDependents
- DependenciesDependencies
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.14.0</version>
</dependency><?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2008 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.code.gson</groupId>
<artifactId>gson-parent</artifactId>
<version>2.14.0</version>
</parent>
<artifactId>gson</artifactId>
<name>Gson</name>
<licenses>
<license>
<name>Apache-2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<properties>
<!-- Make the build reproducible, see root `pom.xml` -->
<!-- This is duplicated here because that is recommended by `artifact:check-buildplan` -->
<project.build.outputTimestamp>2026-04-23T18:59:45Z</project.build.outputTimestamp>
<excludeTestCompilation>**/Java17*</excludeTestCompilation>
</properties>
<dependencies>
<!-- This dependency can be considered optional; omitting it during runtime will most likely
not cause any issues. However, it is not declared with `<optional>true</optional>` because
that can lead to cryptic compiler warnings for consumers, and to be on the safe side in case
there are actually issues which could occur when the dependency is missing at runtime.
See also discussion at https://github.com/google/gson/pull/2320#issuecomment-1455233938 -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.48.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>33.5.0-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.5.0-jre</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--
Plugins for source generation and compilation
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>filtering-java-templates</id>
<goals>
<goal>filter-sources</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java-templates</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/java-templates</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Adjust standard `default-compile` execution -->
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<!-- module-info.java is compiled using ModiTect -->
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
<!-- Adjust standard `default-testCompile` execution -->
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<testExcludes>
<exclude>${excludeTestCompilation}</exclude>
</testExcludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>6.4.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[
Bundle-SymbolicName: com.google.gson
Bundle-Name: ${project.name}
Bundle-Description: ${project.description}
Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: ${project.parent.url}
# Optional dependency for JDK's sun.misc.Unsafe
# Optional dependency to google.errorprone
# https://bnd.bndtools.org/chapters/920-faq.html#remove-unwanted-imports-
Import-Package: sun.misc;resolution:=optional, com.google.errorprone.*;resolution:=optional, *
-removeheaders: Private-Package
-exportcontents:\
com.google.gson,\
com.google.gson.annotations;-noimport:=true,\
com.google.gson.reflect,\
com.google.gson.stream
]]></bnd>
</configuration>
</execution>
</executions>
</plugin>
<!--
Plugins for test execution
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Deny illegal access, this is required for ReflectionAccessTest -->
<!-- Requires Java >= 9; Important: In case future Java versions
don't support this flag anymore, don't remove it unless CI also runs with
that Java version. Ideally would use toolchain to specify that this should
run with e.g. Java 11, but Maven toolchain requirements (unlike Gradle ones)
don't seem to be portable (every developer would have to set up toolchain
configuration locally). -->
<argLine>--illegal-access=deny</argLine>
</configuration>
</plugin>
<!-- Failsafe plugin for running integration tests against final JAR, see `*IT.java` test classes -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<id>obfuscate-test-class</id>
<phase>process-test-classes</phase>
<goals>
<goal>proguard</goal>
</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.8.2</version>
</dependency>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-core</artifactId>
<version>9.3.2</version>
</dependency>
</dependencies>
<configuration>
<skip>${maven.test.skip}</skip>
<obfuscate>true</obfuscate>
<injar>test-classes-obfuscated-injar</injar>
<outjar>test-classes-obfuscated-outjar</outjar>
<inFilter>**/*.class</inFilter>
<proguardInclude>${project.basedir}/src/test/resources/testcases-proguard.conf</proguardInclude>
<libs>
<lib>${project.build.directory}/classes</lib>
<lib>${java.home}/jmods/java.base.jmod</lib>
</libs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>pre-obfuscate-class</id>
<!--
Note: This has to run after test compilation is already done; ideally would use `process-test-classes`
phase here, but the problem is that within this phase maven-resources-plugin has to run twice:
1. maven-resources-plugin: copy original classes
2. proguard-maven-plugin: obfuscate classes
3. maven-resources-plugin: copy obfuscated classes back
But Maven does not permit declaring the same plugin at different positions in the POM. Therefore have
to use a phase before `process-test-classes` here, and rely on the compiler plugin already being done.
-->
<phase>test-compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<skip>${maven.test.skip}</skip>
<outputDirectory>${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.directory}/test-classes/com/google/gson/functional</directory>
<includes>
<include>EnumWithObfuscatedTest.class</include>
<include>EnumWithObfuscatedTest$Gender.class</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>post-obfuscate-class</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<skip>${maven.test.skip}</skip>
<outputDirectory>${project.build.directory}/test-classes/com/google/gson/functional</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.directory}/test-classes-obfuscated-outjar/com/google/gson/functional</directory>
<includes>
<include>EnumWithObfuscatedTest.class</include>
<include>EnumWithObfuscatedTest$Gender.class</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!--
Plugins for building / modifying artifacts
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<!-- Use existing manifest generated by bnd-maven-plugin -->
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<!-- Add module-info to JAR, see https://github.com/moditect/moditect#adding-module-descriptors-to-existing-jar-files -->
<!-- Uses ModiTect instead of separate maven-compiler-plugin executions
for better Eclipse IDE support, see https://github.com/eclipse-m2e/m2e-core/issues/393 -->
<!-- Note: For some reason this has to be executed before javadoc plugin; otherwise `javadoc:jar` goal fails
to find source files -->
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.3.0.Final</version>
<executions>
<execution>
<id>add-module-info</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<jvmVersion>9</jvmVersion>
<module>
<moduleInfoFile>${project.build.sourceDirectory}/module-info.java</moduleInfoFile>
</module>
<!-- Overwrite the previously generated JAR file, if any -->
<overwriteExistingFiles>true</overwriteExistingFiles>
</configuration>
</execution>
</executions>
</plugin>
<!-- Note: Javadoc plugin has to be run in combination with >= `package` phase,
e.g. `mvn package javadoc:javadoc`, otherwise it fails with
"Aggregator report contains named and unnamed modules" -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
</configuration>
</plugin>
<!--
Plugin for deploying to Maven Central
(configured in parent POM)
-->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>JDK17</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<properties>
<maven.compiler.testRelease>17</maven.compiler.testRelease>
<excludeTestCompilation />
</properties>
</profile>
<!-- For JDK 25+ skip tests which rely on ProGuard because it does not support JDK 25 yet -->
<!-- TODO: Remove this once ProGuard supports JDK 25, and there is a solution for https://github.com/Guardsquare/proguard/issues/473 -->
<profile>
<id>JDK25</id>
<activation>
<jdk>[25,)</jdk>
</activation>
<properties>
<excludeTestCompilation>com/google/gson/functional/EnumWithObfuscatedTest.java</excludeTestCompilation>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- Profile for building a subset of Gson; can be executed with `mvn clean test -pl gson -P gson-subset` -->
<profile>
<id>gson-subset</id>
<properties>
<gsonSubsetSrcDir>${project.build.directory}/gson-subset-src</gsonSubsetSrcDir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>prepare-gson-subset-src</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${gsonSubsetSrcDir}</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.sourceDirectory}</directory>
<includes>
<include>com/google/gson/FormattingStyle.java</include>
<include>com/google/gson/JsonArray.java</include>
<include>com/google/gson/JsonElement.java</include>
<include>com/google/gson/JsonIOException.java</include>
<include>com/google/gson/JsonNull.java</include>
<include>com/google/gson/JsonObject.java</include>
<include>com/google/gson/JsonParseException.java</include>
<include>com/google/gson/JsonParser.java</include>
<include>com/google/gson/JsonPrimitive.java</include>
<include>com/google/gson/JsonStreamParser.java</include>
<include>com/google/gson/JsonSyntaxException.java</include>
<include>com/google/gson/Strictness.java</include>
<include>com/google/gson/TypeAdapter.java</include>
<include>com/google/gson/package-info.java</include>
<include>com/google/gson/stream/JsonReader.java</include>
<include>com/google/gson/stream/JsonScope.java</include>
<include>com/google/gson/stream/JsonToken.java</include>
<include>com/google/gson/stream/JsonWriter.java</include>
<include>com/google/gson/stream/MalformedJsonException.java</include>
<include>com/google/gson/stream/package-info.java</include>
<!-- Internal classes used by the classes above -->
<include>com/google/gson/internal/JsonReaderInternalAccess.java</include>
<include>com/google/gson/internal/LazilyParsedNumber.java</include>
<include>com/google/gson/internal/LinkedTreeMap.java</include>
<include>com/google/gson/internal/NonNullElementWrapperList.java</include>
<include>com/google/gson/internal/NumberLimits.java</include>
<include>com/google/gson/internal/Streams.java</include>
<include>com/google/gson/internal/TroubleshootingGuide.java</include>
<include>com/google/gson/internal/bind/JsonElementTypeAdapter.java</include>
<include>com/google/gson/internal/bind/JsonTreeReader.java</include>
<include>com/google/gson/internal/bind/JsonTreeWriter.java</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<!-- Overwrite default compilation execution; otherwise the default would run as well and maven-compiler-plugin
seems to include `target/classes` as classpath for compilation, so custom compilation setup here would
succeed even if classes are missing (because in that case they are taken from the classpath) -->
<!-- Alternative would be to use a custom id here, e.g. 'gson-subset', and then run with
`mvn ... compiler:compile@gson-subset` -->
<id>default-compile</id>
<configuration>
<!-- Use custom source root dir; using the default `src/main/java` would otherwise implicitly
compile needed classes, even if they are not explicitly listed in `<includes>` -->
<compileSourceRoots>${gsonSubsetSrcDir}</compileSourceRoots>
</configuration>
</execution>
<execution>
<!-- Overwrite default test compilation execution, to only build a subset of the tests -->
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<testIncludes>
<testInclude>com/google/gson/internal/bind/JsonTreeReaderTest.java</testInclude>
<testInclude>com/google/gson/internal/bind/JsonTreeWriterTest.java</testInclude>
<testInclude>com/google/gson/internal/LazilyParsedNumberTest.java</testInclude>
<testInclude>com/google/gson/internal/LinkedTreeMapSuiteTest.java</testInclude>
<testInclude>com/google/gson/internal/LinkedTreeMapTest.java</testInclude>
<testInclude>com/google/gson/internal/StreamsTest.java</testInclude>
<testInclude>com/google/gson/stream/JsonReaderPathTest.java</testInclude>
<testInclude>com/google/gson/stream/JsonReaderTest.java</testInclude>
<testInclude>com/google/gson/stream/JsonWriterTest.java</testInclude>
<testInclude>com/google/gson/JsonArrayAsListSuiteTest.java</testInclude>
<testInclude>com/google/gson/JsonArrayAsListTest.java</testInclude>
<testInclude>com/google/gson/JsonArrayTest.java</testInclude>
<testInclude>com/google/gson/JsonNullTest.java</testInclude>
<testInclude>com/google/gson/JsonObjectAsMapSuiteTest.java</testInclude>
<testInclude>com/google/gson/JsonObjectAsMapTest.java</testInclude>
<testInclude>com/google/gson/JsonObjectTest.java</testInclude>
<testInclude>com/google/gson/JsonParserParameterizedTest.java</testInclude>
<testInclude>com/google/gson/JsonPrimitiveTest.java</testInclude>
<testInclude>com/google/gson/JsonStreamParserTest.java</testInclude>
<testInclude>com/google/gson/SubsetTest.java</testInclude>
<testInclude>com/google/gson/TypeAdapterTest.java</testInclude>
</testIncludes>
</configuration>
</execution>
</executions>
</plugin>
<!-- Skip ProGuard execution configured above for obfuscation tests; they cannot run for Gson subset -->
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>