Cannot use plugin tasks due to "org.gradle.api.tasks.bundling.Jar.getArchivePath()" because "jar" is null
See original GitHub issueI’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:
- Created a year ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah! Use this appengine configuration: https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/410#issuecomment-1207646519
If anyone is interested the reason why
jar {}
worked, is because it forced Gradle to eagerly create and configure (with nothing) thejar
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-L96Notice 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 usedtasks.named
ortasks.getByName
directly, then that would look in the right (Task) container and the plugin would not get null.