What is the difference between
include “:directory/project”
and
include “directory:project”
?
Why would you use one over the other? I have seen both used with ‘directory’ being empty of a build.gradle.
What is the difference between
include “:directory/project”
and
include “directory:project”
?
Why would you use one over the other? I have seen both used with ‘directory’ being empty of a build.gradle.
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.
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”
Cheers,
Stuart
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 -> task.name == 'install'} }
Yes, the :
separates logical project paths.
Hi Stefan,
That worked like a charm!!! Thank you very much.
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:’).
Cheers,
Stuart
You don’t need path
, you just need to use :
instead of /
.
I have not figured out what the semantics difference is between
include ‘sub:project1’
and
compile project(':sub:project1')
If I want to run a task in the root project only I use
gradle :task
wheras
gradle task
does some magic and runs ‘task’ in any subproject it can find – but doesn’t complain if a subproject doesnt have ‘task’
Running
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”
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).
gradle task
is a task selector which will select all tasks of that name.gradle :task
is a task in a single project.
I actually find this piece of information hard to find. Do you have a link to the official docs that outlines this difference, @st_oehme?
On a related note, I realized that gradle dependencies
does not seem to behave like a task selector, as it does not execute the dependencies
task across all subprojects, but only for the root project, just like gradle :dependencies
does. I this intended @st_oehme?
Looks like this is very briefly mentioned at Command-Line Interface.
Apparently the dependencies
task is special and does not function as a task selector, but always executes on a single project, see View and Debug Dependencies.