So I need to copy the outputs of a couple projects in a Gradle composite project to a local directory. Normally, in a single build, it would go like this:
tasks{
register<Copy>("copyJarToLocalServer"){
from(jar) // autowires to jar.outputs.files , the outputs of the jar task
into("some\\dir")
}
}
Now I need to do the same thing from a composite build; I used includeBuild to include some projects.
The problem is that I cannot find a way to grab the output from the 'jar' tasks from those included projects.
This unanswered question seems to have a similar problem.
Things I tried
I tried getting the task from gradle.includedBuild:
register<Copy>("copyJarToLocalServer") {
from(gradle.includedBuild("witheronia-maze").task("jar")) // witheronia-maze is one of the included builds
into("some\\dir")
}
This doesn't work because includedBuild().task() returns a TaskReference, not the actual task.
I tried getting all the tasks that have that name recursively:
register<Copy>("copyJarToLocalServer") {
from(getTasksByName(":jar", true).flatMap { it.outputs.files }) // Also tried "jar", ":witheronia-maze:jar" etc.
into("some\\folder")
}
This gives the task output NO-SOURCE and doesn't do anything
I tried getting the project and then getting the task
from(project("witheronia-maze").getTasksByName("jar", false).flatMap { it.outputs.files })
// or
from(project("witheronia-maze").tasks.findByPath("jar"))
This tells me the project was not found in root project, also tried "../witheronia-maze" (actual path), ":witheronia-maze" ( I think an included build is not actually considered a project )
Can someone point me in the right direction? Thanks!
The problem here is that I used
includeBuildto include the other project's build. This does not add it as a project, and you can't access it's tasks. I solved this by usingincludeinstead and setting the project path.The final Copy task now looks like this:
EDIT: The above is not the solution.
includedoes make the tasks resolve correctly, but dependencies do not get substituted anymore and won't resolve. I now use a task in the dependencies that copies the required artifacts to a folder in/build:And then in the composite build: