[Solved] Custom task - dependsOn does not run the dependend task first

issue-resolved

(Florian Pattke) #1

Hello,

I’m still getting started with Gradle, but thought I already understood it. For a project I’m using the distribution plugin, and want to write a task that depends on :installDist

Here is the snippet how I define the task:

allprojects {
	apply plugin: "distribution"
	/* other stuff */
	task integrate(type: Copy) {
		group "distribution"
		dependsOn ":installDist"
		
		into "$project.rootDir/../integration"
		from "$project.buildDir/install/$project.name"
	}
}

When I run the integrate task I expected that :installDist would be executed first. So that I can copy the files from the install folder to its destination. But the logging says:

:installDist NO-SOURCE
:integrate NO-SOURCE
:org.cap5lut.ds.api:integrate NO-SOURCE
:org.cap5lut.ds.core:integrate NO-SOURCE
:org.cap5lut.ds.runner:integrate NO-SOURCE

BUILD SUCCESSFUL in 0s

It is a multi-project, the main project is still just an empty wrapper, same goes so far for ds.api and ds.core. The important part is, that ds.runner has already some code, so it should not respond with NO-SOURCE. If I run :installDist before :integrate, :integrate works fine.

What exactly am I doing wrong/did I misunderstand?

Thanks for your help in advance.


(Stefan Wolf) #2

Hi Florian,

Does it work if you use dependsOn 'installDist' instead of dependsOn ':installDist' (notice the :)?

You could also use dependsOn installDist instead of passing a String to dependsOn.

The : references to the root project. So :installDist is the installDist task in the root project while installDist is the task in the current project.

Cheers,
Stefan


(Florian Pattke) #3

Hello Stefan,

the : was the problem, seems I read over it at some point. It is working now as expected, no matter if pass it as string or dependsOn installDist directly.

Thanks a lot!