Hello!
I’m struggling with something, and I was wondering if you could give me any help with it.
I have several java projects, in several git repositories, all using gradle with some custom plugins. Each repository/project can contain multiple sub-projects, and dependencies between sub-projects are project dependencies. However, dependencies towards other projects are regular dependencies, with published jar and so on.
For development, I’ve made a little gradle plugin that sits in my ~/.gradle/init.d that intercepts the eclipse classpath to transform LibraryDependencies into ProjectDependencies with the proper path : and it works great!
However, I have a small issue and I can’t seem to find a way to fix it. ***First of all, yes I know ! My issue comes from a bad usage and it should not be used that way. I know, but I just can’t do otherwise for now.
So, my issue is when buildship is mixed with the gradle task eclipse (***). The issue is that when the gradle task is executed, it adds into the .classpath file an entry toward my project like so:
<classpathentry kind="src" path="/b">
<attributes>
<attribute name="without_test_code" value="true"/>
</attributes>
</classpathentry>
But then, when the project is imported/refreshed via buildship into eclipse, it does not remove this entry from .classpath when it regenerates the classpath file and therefore the dependency is kept in eclipse as a project dependency, outside buildship dependencies.
But my biggest issue is that I have some specific conditions to transform my dependency as a project dependency or not, and I need these conditions to be re-evaluated everytime I refresh my project. But as soon as the eclipse task has been run once (*** yes I know, I should not), my project is then broken for buildship use until I manually clean up the .classpath file.
Technically, the issue is that neither in beforeMerged nor in whenMerged my entry in the xml classpath appears, and I just can’t find a way to remove it.
You can reproduce with a simple gradle project with the following code in its build.gradle:
afterEvaluate {
project.eclipse.classpath.file {
beforeMerged {
entries.each { println("Before: " + it) }
}
whenMerged {
entries.each { println("After: " + it) }
def projectDep = new org.gradle.plugins.ide.eclipse.model.ProjectDependency("/" + (Math.random() < 0.5 ? "a" : "b"));
projectDep.entryAttributes.put("without_test_code", true);
entries.add(projectDep);
}
}
}
And have 2 empty projects “a” and “b” in eclipse.
If you import via buildship => it works, you either depend on a or b, and with each refresh you re-flip the coin.
However, if you run eclipse task, a or b will be set in the .classpath file, and will stay there, no matter how many time you refresh in buildship.
But the entry is not visible in the eclipse classpath in gradle:
After: Output{path='bin/default'}
After: SourceFolder{path='src/main/java', dir='/home/.../tmp/eclipse-test/app/src/main/java', nativeLibraryLocation='null', exported=false, accessRules=[], output='bin/main', excludes=[], includes=[]}
After: Container{path='org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/', nativeLibraryLocation='null', exported=false, accessRules=[]}
> Task :nothing UP-TO-DATE
After: Output{path='bin/default'}
After: SourceFolder{path='src/main/java', dir='/home/.../tmp/eclipse-test/app/src/main/java', nativeLibraryLocation='null', exported=false, accessRules=[], output='bin/main', excludes=[], includes=[]}
After: Container{path='org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/', nativeLibraryLocation='null', exported=false, accessRules=[]}
So, is there a way to clean-up the .classpath when buildship resynchronize?
Thanks