Reputation: 453
It seems the Exec commandLine does not look into the workingDir for the executable command, instead searching the environment.
If your project structure is the following:
+ projectRoot
+ libraryMod
- build.gradle
+ app
- gradlew
- build.gradle
and you want to run
./gradlew -b ../libraryMod/build.gradle someTask
as an exec:
exec{
workingdir = getAbsolutePath("../app")
commandLine = ['./gradlew', '-b ../libraryMod/build.gradle', 'someTask]
}
returns
[org.gradle.process.internal.DefaultExecHandle] Starting process 'command 'gradlew''. Working directory: /Users/dev/app Command: gradlew -b /Users/dev/libraryMod/build.gradle sometask
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Environment for process 'command 'gradlew'': {PATH=/usr/local/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin, SHELL=/bin/bash, JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home, JAVA_MAIN_CLASS_29464=org.gradle.wrapper.GradleWrapperMain, TERM=xterm-256color, OLDPWD=/Users/dev/java/android/api/TestApp, USER=dev, TMPDIR=/var/folders/gj/c0vstk4s0c5632d92hp72prxy5h3g7/T/, APP_NAME_29464=Gradle, SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.HaOOxHKo1q/Listeners, DISPLAY=/private/tmp/com.apple.launchd.G54BIfEQjR/org.macosforge.xquartz:0, XPC_FLAGS=0x0, __CF_USER_TEXT_ENCODING=0x7C580DE7:0x0:0x0, Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.pUgDDkEH6R/Render, APP_ICON_29464=/Users/dev/app/media/gradle.icns, LOGNAME=dev, LC_CTYPE=en_US.UTF-8, XPC_SERVICE_NAME=0, PWD=/Users/dev/app, SHLVL=1, HOME=/Users/dev, BUILD_NUM=802}
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command 'gradlew'.
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command 'gradlew'' finished with exit value -1 (state: FAILED)
Is there a way to use exec such that the commandLine first argument looks in the workingDir?
I can run this successfully as a task:
task publishAAR(type:GradleBuild){
description 'publish the lib module aar bundle to artifactory'
buildFile = libModScript
tasks = ['someTask']
}
but need to incorporate into a larger build file using exec.
Upvotes: 2
Views: 4276
Reputation: 13476
Try instead setting the executable to the absolute path of the gradlew file.
exec {
executable "${projectDir}/gradlew"
}
Upvotes: 0