似乎Exec commandLine没有查看可执行命令的workingDir,而是搜索环境。
如果您的项目结构如下:
+ projectRoot
+ libraryMod
- build.gradle
+ app
- gradlew
- build.gradle
你要运行
./gradlew -b ../libraryMod/build.gradle someTask
作为执行官:
exec{
workingdir = getAbsolutePath("../app")
commandLine = ['./gradlew', '-b ../libraryMod/build.gradle', 'someTask]
}
返回
[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)
有没有办法使用exec,以便commandLine第一个参数在workingDir中查找?
我可以成功地将其作为一项任务运行:
task publishAAR(type:GradleBuild){
description 'publish the lib module aar bundle to artifactory'
buildFile = libModScript
tasks = ['someTask']
}
但需要使用exec合并到更大的构建文件中。
答案 0 :(得分:0)
尝试将可执行文件设置为 gradlew 文件的绝对路径。
exec {
executable "${projectDir}/gradlew"
}