diff --git a/gson/pom.xml b/gson/pom.xml
index 13c2515a..0063f1cb 100644
--- a/gson/pom.xml
+++ b/gson/pom.xml
@@ -17,7 +17,7 @@
test
-
+
@@ -56,6 +56,23 @@
org.apache.felixmaven-bundle-plugin
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ filtering-java-templates
+
+ filter-sources
+
+
+ ${basedir}/src/main/java-templates
+ ${project.build.directory}/generated-sources/java-templates
+
+
+
+
diff --git a/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java b/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java
new file mode 100644
index 00000000..73c61546
--- /dev/null
+++ b/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2018 The Gson authors
+ *
+ * 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.
+ */
+
+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.
+ *
+ * @author Inderjeet Singh
+ */
+public final class GsonBuildConfig {
+ // Based on https://stackoverflow.com/questions/2469922/generate-a-version-java-file-in-maven
+
+ /** This field is automatically populated by Maven when a build is triggered */
+ public static final String VERSION = "${project.version}";
+}
diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java
index 5b1c6c83..b19302da 100644
--- a/gson/src/main/java/com/google/gson/Gson.java
+++ b/gson/src/main/java/com/google/gson/Gson.java
@@ -37,6 +37,7 @@ import java.util.concurrent.atomic.AtomicLongArray;
import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.Excluder;
+import com.google.gson.internal.GsonBuildConfig;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Streams;
import com.google.gson.internal.bind.ArrayTypeAdapter;
@@ -461,7 +462,7 @@ public final class Gson {
return candidate;
}
}
- throw new IllegalArgumentException("GSON cannot handle " + type);
+ throw new IllegalArgumentException("GSON (" + GsonBuildConfig.VERSION + ") cannot handle " + type);
} finally {
threadCalls.remove(type);
@@ -703,6 +704,8 @@ public final class Gson {
((TypeAdapter