Problem with path variables and Idea plugin

(Sten Roger Sandvik) #1


I have a problem with the Idea plugin on M7 (this is also a problem on M5 and M6 also). I want to generate the idea files so that the gradle dependency directory is replaced with a path variable.

So, in my case /Users/srs/.gradle directory is replaced by $GRADLE_HOME$. When I do not do any pathVariable replacement I see that the dependencies in .iml file is like this:


Which is nice, but when I configure it like this:

idea {

pathVariables GRADLE_HOME: gradle.gradleUserHomeDir


Then the same xml snippet shows up like this:


It’s a problem for idea to have it like the one above without extensions. So, how come it changes behaviour? Have I done something wrong here?


(Adrian Abraham) #2

I reported this as GRADLE-1844, but no one has looked at it yet :frowning:

In my own scripts, I’m using the withXml hook to manually replace all instances of gradle.gradleUserHomeDir with $GRADLE_USER_HOME$, and it works well enough.

(Szczepan Faber) #3

Hmmm, I may not understand the problem correctly,

It’s a problem for idea to have it like the one above without extensions.

What do you mean ‘problem without extensions’? Can you include more information (like expected vs actual results, etc.)


(Peter Niederwieser) #4

I think he means no file extension (e.g. “.jar”). Sounds like we are using canonicalFile/canonicalPath where we shouldn’t.

(Sten Roger Sandvik) #5

Yes, when IntelliJ encounters dependencies without the .jar extension it just does not load it.

(Sten Roger Sandvik) #6

I found that bug report just right after I posted the problem. Seems to have been there since M5. Do any Gradle committers have a solution on this?

(Sten Roger Sandvik) #7

Result without setting pathVariable…


Result after setting pathVariable…


And the expected (after setting pathVariable)…


(Peter Niederwieser) #8

Sounds like this will require a bug fix. Now that our cache layout has changed, we’ll probably have to change the IDEA plugin not to use canonicalPath/canonicalFile anywhere. You can either vote on this issue or send a pull request.

(Sten Roger Sandvik) #9

To come around this error I did (as pointed out by Adrian) the following:

idea {
  module {
    iml {
      withXml { provider ->
        provider.node.depthFirst().root.each {
   it.@url = it.@url.replace(gradle.gradleUserHomeDir.toString(), '$GRADLE_USER_HOME$')