Problem with path variables and Idea plugin

Hi.

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:

jar:///Users/srs/.gradle/caches/artifacts-7/artifacts/56865c09425cc6ecda8606d7e6035ceb/javax.servlet/servlet-api/2.5/jar/servlet-api-2.5.jar!/

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:

file://$GRADLE_HOME$/caches/artifacts-7/filestore/998/9986f2db44c7d183a861e72d3003eea1fcfe7a99

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?

Thanks!

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.

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.)

Cheers!

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

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

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?

Result without setting pathVariable…

jar:///Users/srs/.gradle/caches/artifacts-7/artifacts/56865c09425cc6ecda8606d7e6035ceb/javax.servlet/servlet-api/2.5/jar/servlet-api-2.5.jar!

Result after setting pathVariable…

file://$GRADLE_HOME$/caches/artifacts-7/filestore/998/9986f2db44c7d183a861e72d3003eea1fcfe7a99

And the expected (after setting pathVariable)…

jar://$GRADLE_HOME$/caches/artifacts-7/artifacts/56865c09425cc6ecda8606d7e6035ceb/javax.servlet/servlet-api/2.5/jar/servlet-api-2.5.jar!

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.

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$')
 }
      }
    }
  }
}