question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use plugin tasks due to "org.gradle.api.tasks.bundling.Jar.getArchivePath()" because "jar" is null

See original GitHub issue

I’ve a minimal Spring Boot application using Java 17 and I’m trying to get AppEngine Gradle plugin to work…

As documented I have set it up like:

settings.gradle:

pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id.startsWith("com.google.cloud.tools.appengine")) {
                useModule("com.google.cloud.tools:appengine-gradle-plugin:${requested.version}")
            }
        }
    }
}

build.gradle:

plugins {
	id "java"
	id "com.google.cloud.tools.appengine-appyaml" version "2.4.4"
	id "io.spring.dependency-management" version "1.0.12.RELEASE"
	id "org.springframework.boot" version "2.6.10"
}

group = "com.github.marceloverdijk"
version = "0.0.1-SNAPSHOT"
sourceCompatibility = "17"

ext {
	set("springCloudVersion", "2021.0.3")
	set("springCloudGcpVersion", "3.3.0")
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencyManagement {
	imports {
		mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:${springCloudGcpVersion}"
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

dependencies {
	// implementation "com.google.cloud:spring-cloud-gcp-starter"
	implementation "org.apache.commons:commons-lang3"
	implementation "org.springframework.boot:spring-boot-starter-actuator"
	implementation "org.springframework.boot:spring-boot-starter-jetty"
	implementation("org.springframework.boot:spring-boot-starter-web") {
		exclude module: "spring-boot-starter-tomcat"
	}
	annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
	developmentOnly "org.springframework.boot:spring-boot-devtools"
	testImplementation "org.springframework.boot:spring-boot-starter-test"
}

appengine {
	tools {
                // https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/431
		cloudSdkHome = "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
	}
	deploy {
		projectId = "GCLOUD_CONFIG"
		version = "GCLOUD_CONFIG"
		promote = true
		stopPreviousVersion = true
	}
}

tasks.named("test") {
	useJUnitPlatform()
}

but when running any GAE tasks I get:

❯ ./gradlew appengineShowConfiguration

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'aircraft-notifier'.
> Cannot invoke "org.gradle.api.tasks.bundling.Jar.getArchivePath()" because "jar" is null

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 587ms

Even the bootRun tasks now fails:

❯ ./gradlew bootRun

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'aircraft-notifier'.
> Cannot invoke "org.gradle.api.tasks.bundling.Jar.getArchivePath()" because "jar" is null

If I remove just the appengine { .. } configuration block from build.gradle (so GAE plugin itself still configured) the app starts up again with bootRun

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
elefeintcommented, Aug 11, 2022
0reactions
TWiStErRobcommented, Nov 23, 2022

If anyone is interested the reason why jar {} worked, is because it forced Gradle to eagerly create and configure (with nothing) the jar Task. This task is used by: https://github.com/GoogleCloudPlatform/app-gradle-plugin/blob/f50be8dcdde14ec6ef94947f1e21f5ea855be792/src/main/java/com/google/cloud/tools/gradle/appengine/appyaml/AppEngineAppYamlPlugin.java#L95-L96

Notice the getProperties().get("jar"), that triggers some magical Groovy path to resolve the property, but since Gradle is lazy, the task is not materialized yet as a property. If this plugin used tasks.named or tasks.getByName directly, then that would look in the right (Task) container and the plugin would not get null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Cloud SDK Throwing NullPointerException While ...
Summary Google Cloud App Engine Gradle plugin throwing NullPointerException when any Gradle task is executed. Not sure why.
Read more >
Not finding org.gradle.api.tasks.bundling.Jar in gradle-core ...
Hello, I'm writing a custom plugin in Groovy that defines a new task for building a Jar file. I get no complaints from...
Read more >
Authoring Tasks - Gradle User Manual
You can access tasks from any project using the task's path using the tasks.getByPath() method. You can call the getByPath() method with a...
Read more >
Jar - Gradle DSL Version 7.6
The extension part of the archive name. fileMode. The Unix permissions to use for the target files. null means that existing permissions are...
Read more >
Developing Custom Gradle Plugins
Generally, this JAR might include some plugins, or bundle several related task classes into a single library. Or some combination of the two....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found