Include ":directory/project" vs include "directory:project"

(trisport88) #1

What is the difference between

include “:directory/project”


include “directory:project”


Why would you use one over the other? I have seen both used with ‘directory’ being empty of a build.gradle.

Empty directory grouping subprojects
(Stefan Oehme) #2

The first is an error. I don’t exactly know why people keep doing it, but we will add a warning to Gradle for that soon. It works accidentally in some cases, but generally will fail in weird ways.

The second one is the right way and what is shown in all documentation.

(trisport88) #3

Hi Stefan,

Thanks for your reply.

When I use 'include “directory:project” my build fails. I think because I have a task in the top level build.gradle that does dependsOn subprojects.install. When I run ‘gradle clean’ from the top level it fails with the error:

Could not get unknown property ‘install’ for project ‘:directory’ of type org.gradle.api.Project.

Is there a way around this? Do I need to include an ‘do nothing’ build.gradle for the empty directory?

Also if there are multiple empty directories should it be written as follows? :-

include “directory1:directory2:project”



(Stefan Oehme) #4

This code assumes that all subprojects have an install task, which is not necessarily true. Here’s a snippet that finds all install tasks in all subprojects:

subprojects.collectMany { sub -> sub.tasks.matching { task -> == 'install'} }

Yes, the : separates logical project paths.

(trisport88) #5

Hi Stefan,

That worked like a charm!!! Thank you very much. :sunglasses:

I added:

include "directory:project1"
include “directory1:directory2:project2”

In order to get the dependencies working I had to change from this:

compile project(’:directory/project’)

to this:

compile project(path: ‘:directory:project’)

Originally I tried without the colon in front of the ‘directory’ but that did not work. I also had to add ‘path:’.

I am a gradle novice so this has been a bit of trial and error. Thanks to your advice I hope I am now moving in the right direction (please let me know if the way I am expressing the dependencies is wrong as I don’t really understand the difference with and without ‘path:’).



(Stefan Oehme) #6

You don’t need path, you just need to use : instead of /.

(David Lee) #7

I have not figured out what the semantics difference is between

include ‘sub:project1’


compile project(':sub:project1')

If I want to run a task in the root project only I use

gradle :task


gradle task

does some magic and runs ‘task’ in any subproject it can find – but doesn’t complain if a subproject doesnt have ‘task’


gradle ':subproject:task'

runs only the subproject’s task

But then so does

gradle 'subproject:task'

if ‘task’ is ‘projects’ they both print the same “:subproject”

(Stefan Oehme) #8

gradle task is a task selector which will select all tasks of that name. gradle :task is a task in a single project.

sub:project1 is a relative project path (relative to the project you’re currently in), :sub:project1 is an absolute project path. Relative paths can sometimes be more convenient (when you have lots of projects in a deep hierarchy).