Closed heathen00 closed 2 years ago
Sorry I thought I had replied to this. I wasn't really able to recreate it. If you could provide a minimal project that does it will help us debug. The jar property has been working for a while, so I don't know what's going on here
Hello, I have the same issue. It seems to be caused by "Task Configuration Avoidance" introduced in Gradle 5.1.
It happens when you don't trigger any code in your build.gradle file that configures the Gradle Jar task. The reason is that since Gradle 5.1 when you apply the java plugin to your project the Jar task is by default only registered but not configured/created if you don't explicitly do so. The way AppEngineAppYamlPlugin gets the Jar task does not trigger the creation if the task has only been registered and thus gets a null reference causing NPE later.
A quick fix for users of the App Engine Gradle plugin is to do something in the build.gradle file that creates the Jar task. Adding following line should be sufficient:
jar {}
Possible solution to fix the NPE in the plugin code is to get the Jar (or War) task in a way that makes sure it is created:
diff --git a/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java b/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java
index 28ca50d..d7bbf7f 100644
--- a/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java
+++ b/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java
@@ -89,10 +89,10 @@ public class AppEngineAppYamlPlugin implements Plugin<Project> {
// we can only set the default location of "archive" after project evaluation (callback)
if (stageExtension.getArtifact() == null) {
if (project.getPlugins().hasPlugin(WarPlugin.class)) {
- War war = (War) project.getProperties().get("war");
+ War war = (War) project.getTasks().getByName("war");
stageExtension.setArtifact(war.getArchivePath());
} else if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
- Jar jar = (Jar) project.getProperties().get("jar");
+ Jar jar = (Jar) project.getTasks().getByName("jar");
stageExtension.setArtifact(jar.getArchivePath());
} else {
throw new GradleException("Could not find JAR or WAR configuration");
There might be still some way to avoid Jar task creation for performance reasons if it's not needed for current build but it may require bigger changes in the plugin code.
@pmatousek Thanks for your input! This will be useful for others facing the same issue and/or if we want to fix it in the plugin at some point.
For folks hitting this at the exact same location, a workaround is to simply execute the jar
(or war
) task with our plugin tasks. For example, ./gradlew jar appengineDeploy
. The cause is likely what @pmatousek said: the jar
task may not be created in recent Gradle versions. Note that you do need a JAR (or WAR) to deploy, so running jar
is an implicit requirement.
Summary
Google Cloud App Engine Gradle plugin throwing NullPointerException when any Gradle task is executed. Not sure why. Current workaround, is to remove the plugin from my build.gradle file and deploy my website to Google Cloud using the Google SDK CLI command:
gcloud app deploy ./build/libs/personal-website-undefined.jar
.Details
After I upgraded the version of Kubuntu on my laptop to 20.04.1, I noticed the behaviour that I could no longer build this project since the Google Cloud App Engine Gradle plugin kept throwing a NullPointerException while the plugin was initialising. It doesn't matter what Gradle task I execute the exception is always the same (from './gradlew --stacktrace properties'):
It is a massive stack trace but no other code belonging to the Google Cloud App Engine Gradle Plugin is mentioned after the first line. The rest of the stack trace is just Gradle code.
Although I am no Gradle expert, my interpretation of looking at the code that is throwing the NPE, https://github.com/GoogleCloudPlatform/app-gradle-plugin/blob/master/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java, is it seems as though the code is assuming that the Jar plugin will set a "jar" Gradle property but it isn't. I see no mention of this property in the Gradle Jar plugin documentation, either: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html., not even as a deprecated property. Thus, I really would not expect this assumption to be valid.
My gradle.build file:
My Gradle version details:
My app.yaml: