IDEA fails to import Gradle project
Answered
IDEA Ultimate fails to import Gradle project that contains the following task:
task loadDockerEnvironment() {
def env = new ByteArrayOutputStream();
exec {
commandLine = 'docker-machine env default'.split() // <--- Fails here
standardOutput = env
}
def details = env.toString()
project.ext.dockerEnv = [:]
details.split('\n').findAll { it.startsWith('export') }.collect { it.replace('export ', '').split('=') }.each {
project.ext.dockerEnv[it[0]] = it[1].replaceAll('"', '')
}
}
// The error is:"Cause: error=2, No such file or directory"
// The project builds just fine in the command line. Gradle 2.9, OSX and JDK 1.7
Please sign in to leave a comment.
Any solution or workaround would be appreciated. Thanks!
Depending on how you set environment variables on Mac, IDEA may have different value for PATH, hence when Gradle is started from IDEA, it will not see some binaries. This also depends on OS X version:
http://apple.stackexchange.com/q/51677
http://apple.stackexchange.com/q/57385/17551
http://stackoverflow.com/q/135688/104891
Just echo PATH from a script running in IDEA and compare it to what you see in Terminal. Make it the same and the problem should resolve.
Serge,
Thank you for your prompt reply. Unfortunately that does not seem to do it for me or I'm just failing to see what I need to do.
Here's what I have:
○ → which docker-machine
/usr/local/bin/docker-machine
○ → launchctl getenv PATH
/usr/local/bin:/usr/local/bin:/usr/local/bin:
Based on this, I would think that IDEA should be able to find the docker-machine from the path.
OSX version: 10.11.3
In addition, when importing the project, the "Show log" will not open or show any further detail. Trying to figure out what was going on was hard without such info.
See https://intellij-support.jetbrains.com/hc/articles/207241085 .
Run some script from IDEA that will print PATH to confirm that PATH is the same.
Serge,
Thanks for the info for the log files.
The paths are correct. They are indeed different, but it just happens that I've always been able to execute the tasks from within IDEA. In other words, if you import a project without such task and add the task to it, then the task can be executed just fine from IDEA.
After some more investigation it appears that the issue was simply the way the task was implemented and how it was related to Gradle's execution lyfecycle.
As it appears, the PATH does not get loaded or is available during the "Configuration" phase. Once refactored, the task got the following shape and I was able to import the gradle project just fine. I simply moved all code to the "Execution" phase (see doFirst/doLast lambdas).
Thanks for the help and hints.