I am trying to make sure a classpath entry are present in the .classpath file. Even when I manually add them after running the gradle build the entries are removed.
I don’t understand. Given your ‘build.gradle’, everything you list under ‘manually added’ (except for ‘/ApacheParent’) should already be generated by ‘gradle eclipse’.
What I meant by manually added is I put in the entire through the project properties page in eclipse. What .classpath gradle generates do not have the entries for some reason.
Your example is confusing. Why would you add an entry both with ‘node.appendNode’ and then again manually in the IDE?
As a general answer, the Eclipse plugin doesn’t keep 'classpathentry’s of kind ‘src’, ‘var’, and ‘con’. This is because it generates such entries itself and wouldn’t be able to tell if an encountered entry was previously generated by itself (and needs to be replaced) or added manually (and needs to be kept). Therefore it assumes the common and recommended case, namely that all dependency information is configured in Gradle. Going forward, the STS Gradle plugin may be in a better position to solve such use cases.
Indeed this code works fine for me. I’ve tried with 1.0-milestone-7, but I would also expect this to work with earlier versions.
Maybe there is a misunderstanding here. This code will affect what goes into the ‘.classpath’ file, but that file isn’t used by the STS plugin. You can either use the Gradle Eclipse plugin and then open the generated Eclipse project, or use the STS plugin.
One possible reason some source entries are going missing is if the corresponding source folders do not exist in your project.
Source entries for non-existent folders are ignored. Not sure this is the case here, but do make sure the folders exist before importing or refreshing source folders in STS.
Maybe there is a misunderstanding here. This code will affect what goes into the .classpath file, but that file > isn’t used by the STS plugin. You can either use the Gradle Eclipse plugin and then open the generated
Eclipse project, or use the STS plugin.
Correction. This is not quite true. It would depend on how exactly a project got imported. If a .classpath already exists on import, or if the import wizard is configured to run the ‘eclipse’ task as part of importing. Some of the information that is in the generated .classpath will be retained.
In STS 2.8.1 however source folders will be configured using the tooling API and existing generated source folders will be replaced by what tooling API returns. That being said… would tooling API not be expected to return source folders consistent with what eclipse task would generate? (Unless of course, the folders don’t actually exist).
In STS 2.9.0.RC1 there is now also an option to import with ‘dependency management’ disabled. This will retain most of the information generated by the gradle eclipse task ‘as is’. So assuming the generated .classpath is correct STS import should not mess with it. (But you’ll need to install 2.9.0.RC1 version of STS Gradle tools AND import with the dependency management disabled).