Changing Eclipse Source folder output location generates duplicate classpathentries

I want to change the output location to separate the test classes from my other classes.
I used the code provided in the Buildship 1.0.18 release notes (https://discuss.gradle.org/t/buildship-1-0-18-is-now-available/19012 ):

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                def src = entries.find { it.path == 'src/main/java' }
                src.output = "/$eclipse.project.name/classes/main-java"
            }
        }
    }
}

Note: I don’t use Buildship; I only use the eclipse task to generate my eclipse project.

All works as expected, but when I run the eclipse task a second time, a duplicate (and invalid) classpathEntry is created:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry path="bin" kind="output"/>
    <classpathentry output="/gradleSrcFolderOutput/classes/main-java" kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
</classpath>

Am I doing something wrong?

I think this is an issue on our side, because paths in the Eclipse classpath are unique, so we should overwrite the old entry instead of adding a second one.

As a workaround, if you don’t care about merging the previous state (i.e. user-edited values), you could clean the classpath before merging it

beforeMerge {
  entries.clear()
}

Thanks for the workaround Stefan, I don’t mind losing user-edited values so this fits perfectly.

Should I open a bug?

Please go ahead, yes :slight_smile:

Done: Issue 922.