Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in gradle build.gradle file - how can i check if a project exists?

Let's say in a build.gradle file I want to do something like:

ext.sharepointBuildDir = project(":MainProject:sharepoint").buildDir.path

But in certain configurations that project may not exist.

How can I check "does a gradle project exist"?

like image 883
Nicholas DiPiazza Avatar asked Mar 30 '17 18:03

Nicholas DiPiazza


1 Answers

You can use a findProject method, which is according to it's description

Locates a project by path. If the path is relative, it is interpreted relative to this project.

Returns: The project with the given path. Returns null if no such project exists.

So, you can simply use it as follows:

if (findProject(':MainProject:sharepoint') != null) {
    println 'project exists'
} else {
    println 'project does not exist'
}
like image 99
Stanislav Avatar answered Sep 28 '22 06:09

Stanislav