What's now the correct way with non-deprecated cod...
# community-support
s
What's now the correct way with non-deprecated code for Gradle 8.11 to in a task depend on the output from a task in a different project, implying a task dependency? The code in this thread does not work (anymore).
Copy code
val generatedResourcesDir = layout.buildDirectory.dir("generated-resources/main")
val copyWebAppTemplate by tasks.registering(Copy::class) {
    val webAppTemplateProject = project.project(projects.plugins.reporters.webAppTemplate.path)
    dependsOn(webAppTemplateProject.tasks["yarnBuild"])

    from(webAppTemplateProject.file("build")) {
        include("scan-report-template.html")
    }

    into(generatedResourcesDir)

    if (inputs.sourceFiles.isEmpty) throw StopExecutionException("No input files found.")
    outputs.cacheIf { true }
}
This used to work before Gradle 8.11 to implicitly depend on the
yarnBuild
task from the
webAppTemplate
project, and copy its output HTML file as a resource into this project.
But now running
./gradlew -p plugins/reporters/web-app copyWebAppTemplate./gradlew -p plugins/reporters/web-app copyWebAppTemplate
gets me
> No input files found.
m
You'll need to go through outgoing variants, etc...
s
Thanks for the pointer! But, holy crap, there's no simpler way than with creating a custom configuration?
m
Not that I know of, this is the rite of passage to the isolated projects congregation šŸ˜…
😱 1
You have 2 versions: • One involving attributes (that supports publishing) • One a bit simpler where you just hardcode the producer configuration name in the consumer (doesn't work with publishing) Both cases you need to create a configuration and do the dance
v
And your pattern never really worked.
It was always unsafe and very bad idea and maybe worked a bit somehow under conditions if you were lucky
s
Hmm, the approach with shared configurations doe snot seem to work either, the task in the provider project is not triggered when building the consumer...
The provider has
Copy code
val webAppTemplateConfiguration by configurations.creating {
    isCanBeResolved = false
}

artifacts {
    add(webAppTemplateConfiguration.name, yarnBuild)
}

val yarnInstall by tasks.registering {
    description = "Use Yarn to install the Node.js dependencies."
    group = "Node"

    dependsOn(kotlinYarnSetup)

    inputs.files(".yarnrc", "package.json", "yarn.lock")

    // Note that "node_modules" cannot be cached due to symlinks, see <https://github.com/gradle/gradle/issues/3525>.
    outputs.dir("node_modules")
}

val yarnBuild by tasks.registering {
    description = "Use Yarn to build the Node.js application."
    group = "Node"

    inputs.files(yarnInstall)
    inputs.dir("src")

    outputs.cacheIf { true }
    outputs.dir("build")
}
and the consumer has
Copy code
val webAppTemplateConfiguration by configurations.creating {
    isCanBeConsumed = false
}

dependencies {
    webAppTemplateConfiguration(project(":plugins:reporters:web-app-template", "webAppTemplateConfiguration"))
}

val generatedResourcesDir = layout.buildDirectory.dir("generated-resources/main")
val copyWebAppTemplate by tasks.registering(Copy::class) {
    val webAppTemplate: FileCollection = webAppTemplateConfiguration

    inputs.dir(webAppTemplate)
    from(webAppTemplate) {
        include("scan-report-template.html")
    }

    into(generatedResourcesDir)

    outputs.cacheIf { true }
}
but executing
copyWebAppTemplate
does not execute
yarnBuild
.
Ah, wait, I'm onto something...
Yeah,
tasks.registering
was wrong in my case as my
yarn
tasks are generated by a task rule. I'm now using
tasks.named()
instead to refine configuration of those tasks.