Removing absolute paths from Eclipse .classpath file


(Ken Krebs) #1

It is a nice convenience to have Gradle generate the Eclipse .classpath xml files. It also convenient to version control them. As it stands, Gradle puts absolute file paths to the Gradle cache in these files which is not convenient. I have been working around this by having Gradle replace those paths with an Eclipse pathVariable as described in the EclipseClasspath docs:

eclipse {
 pathVariables 'GRADLE_CACHE': file("${gradle.startParameter.gradleUserHomeDir}/caches/artifacts-4")
}

I then set the Eclipse classpathVariable GRADLE_CACHE to something like ‘C:/Users/Ken/.gradle/caches/artifacts-4’.

This works pretty well until the place where the Gradle cache location changes as it has in the last couple of milestone releases, requiring changes to both the classpathVariable for all developers and the build files referencing it.

It would be nice if Gradle could take care of this. One way to do this would be to introduce a ‘userHome’ property to Eclipse or EclipseClasspath that could be set in the build file. This property value would reference a classpathVariable set by the developer to point to their home directory, i.e. USER_HOME. Gradle could then fill out the rest of path to the cache. If the developer does not set the property, behavior could be the same as it currently is using absolute paths for those who don’t version control the.classpath file.

eclipse {
 userHome = 'USER_HOME'
}

(Ken Krebs) #2

sweet!!!

Now I just set the Eclipse classpathVariable GRADLE_USER_HOME to ‘C:/Users/Ken/.gradle’ and it just works.

it would be nice and very useful to see that example in the dsl EclipseClasspath docs.

thx


(Peter Niederwieser) #3

Does this solve your problem?

eclipse {
    pathVariables 'GRADLE_USER_HOME': gradle.gradleUserHomeDir
}