I'm new to gradle scripting and I'm trying to do something simple. There is an android colors.xml in an artifactory repo inside a tarball. All i want to do is configure gradle so that before it builds it gets that file from the repo (if its changed) and copies it to my android module's res/values/colors.xml. I can do that with npm install on the command line but dont know how to run that from within build.gradle. My first stab is this in my module's build.gradle.
task getResourceTokens(type: Exec) {
workingDir "/Users/cbattle/Dev/DesignTokenTest"
executable 'npm'
args = ['install https://artifactory-lvs.corpzone.internalzone.com/artifactory/.../token-tester-0.0.7.tgz']
doLast {
println "Executed!"
}
}
task copyFiles(type: Copy) {
from '/Users/cbattle/node_modules/.../colors.xml'
into '/Users/cbattle/Dev/DesignTokenTest/atoms/src/main/res/values'
}
copyFiles.dependsOn(getResourceTokens)
preBuild.dependsOn(copyFiles)
This fails with
Execution failed for task ':atoms:getResourceTokens'.
> Process 'command 'npm'' finished with non-zero exit value 1
I have the proper credentials in my .npmrc file. It works if I just use the command line manually. Its not clear why this fails.
I also have https://github.com/node-gradle/gradle-node-plugin installed so it may be possible to use that instead. But the above should work. Any ideas?
Thanks
I figured it out. For whatever reason it seems that the Exec task can not run npm. Instead I installed the handy NodePlugin and used this.
task getTokens(type: NpmTask) {
args = ['install', 'https://artifactory-lvs.corpzone.internalzone.com/artifactory/.../token-tester-0.0.7.tgz']
}
That worked like a charm!