Marian Klühspies
Marian Klühspies

Reputation: 17627

Execute gradle build task from any location

I´m trying to build my gradle projects from other locations than the project folder itself, but it always says it couldn´t find build task.

What I´ve tried so far:

sudo ./myprojects/myapp/gradlew build

sudo ./myprojects/myapp/gradlew ./myprojects/myapp/build

How can I execute a gradle build task from any location?

Upvotes: 16

Views: 11564

Answers (3)

Servet Karabas
Servet Karabas

Reputation: 61

./usmobile-microservice/gradlew -p ./usmobile-microservice clean buildUI

./project_directory/gradlew -p ./project_directory clean build

worked for me

Upvotes: 4

Nikita Tukkel
Nikita Tukkel

Reputation: 2305

You may try this script, which is 90-lines long: https://github.com/dougborg/gdub

Or use this straightforward one-liner I use myself:

function lookupgradle() { 
  find . .. ../.. ../../.. ../../../.. ../../../../.. ../../../../../.. -maxdepth 1 -name 'gradlew' -executable -print -quit
}

alias g='$(lookupgradle)'

If you'll find out that it is still required to specify project directory, add -p .:

alias g='$(lookupgradle) -p .'

Upvotes: 2

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

Various people have written (and published) scripts to execute gradlew from any subproject directory (in a multi-project build). To reliably execute Gradle from any subdirectory, it is necessary to set the "current project directory" via -p. It would be nice to have this restriction lifted (this would make a good feature request).

Upvotes: 18

Related Questions