Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootStartScripts tasks should be an instance of org.gradle.api.tasks.application.CreateStartScripts rather than its superclass org.gradle.jvm.application.tasks.CreateStartScripts #39584

Closed
cpuzicha opened this issue Feb 15, 2024 · 8 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@cpuzicha
Copy link

cpuzicha commented Feb 15, 2024

Output from my own plugin test, built with Gradle 8.6:

The task 'bootStartScripts' (org.gradle.jvm.application.tasks.CreateStartScripts) is not a subclass of the given type (org.gradle.api.tasks.application.CreateStartScripts)

Shouldn't custom tasks prefer the API versions of tasks?
org.gradle.api.tasks.application.CreateStartScripts extends org.gradle.jvm.application.tasks.CreateStartScripts anyway.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 15, 2024
@philwebb
Copy link
Member

@cpuzicha Do you have a way for us to replicate the "The task 'bootStartScripts' (org.gradle.jvm.application.tasks.CreateStartScripts) is not a subclass of the given type (org.gradle.api.tasks.application.CreateStartScripts)" error?

I'm not sure we've seen it in our own tests.

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Feb 15, 2024
@cpuzicha
Copy link
Author

cpuzicha commented Feb 19, 2024

File: build.gradle.kts

plugins {
    id("java")
    id("application")
    id("org.springframework.boot") version "3.2.2"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

tasks.withType(CreateStartScripts::class).forEach {
    logger.lifecycle("Found start script task: ${it.name}")
}

tasks.named("bootStartScripts").get().let {
    logger.lifecycle("${it.name} has class ${it::class.qualifiedName}")
}

tasks.named("bootStartScripts", CreateStartScripts::class) {
    //fails
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 19, 2024
@mhalbritter
Copy link
Contributor

sb-39584.zip

Here's one which we can unzip and use.

@mhalbritter
Copy link
Contributor

If I change in org.springframework.boot.gradle.plugin.ApplicationPluginAction

import org.gradle.jvm.application.tasks.CreateStartScripts;

to

import org.gradle.api.tasks.application.CreateStartScripts;

our build still works.

However I lack the Gradle knowledge to determine if this is the right thing to do.

@wilkinsona
Copy link
Member

It could be argued that this is user error as it's making an assumption about the type of the bootStartScripts task that doesn't hold true. This should work:

tasks.named("bootStartScripts", org.gradle.jvm.application.tasks.CreateStartScripts::class) {
    // works?
}

That said, I don't think there's any good reason for us to be using org.gradle.jvm.application.tasks.CreateStartScripts rather than org.gradle.api.tasks.application.CreateStartScripts. I suspect it's just an accident of auto-completion when I worked on #20759 and perhaps a hangover from #2622.

Given that Gradle implicitly imports the org.gradle.api.tasks.* classes into your build script, there is a good reason for us to be using org.gradle.api.tasks.application.CreateStartScripts. Furthermore, org.gradle.api.tasks.application.CreateStartScripts is a subclass of org.gradle.jvm.application.tasks.CreateStartScripts. I think it's very unlikely that anyone has written a build the relies upon bootStartScripts specifically being an instance of org.gradle.jvm.application.tasks.CreateStartScripts so I think we can safely change to org.gradle.api.tasks.application.CreateStartScripts as a bug fix in 3.1.x.

@wilkinsona wilkinsona changed the title SpringBoot plugin uses wrong task type for 'createStartScripts' inherits wrong class bootStartScripts tasks should be an instance of org.gradle.api.tasks.application.CreateStartScripts rather than its superclass org.gradle.jvm.application.tasks.CreateStartScripts Feb 21, 2024
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Feb 21, 2024
@wilkinsona wilkinsona added this to the 3.1.x milestone Feb 21, 2024
@cpuzicha

This comment was marked as duplicate.

@cpuzicha
Copy link
Author

Any reason this is added to 3.1.x but not to 3.2.x and most importantly the main branch?

@cpuzicha cpuzicha reopened this Feb 23, 2024
@wilkinsona
Copy link
Member

We fix in the oldest affected branch and then merge forwards. The fix will land in 3.1.x and then be merged forwards into 3.2.x and then main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants