Skip to content

Instantly share code, notes, and snippets.

@loverde
Created December 14, 2016 16:15
Show Gist options
  • Save loverde/a58c606c7ef0f36cb2a40e5f2c2c02e1 to your computer and use it in GitHub Desktop.
Save loverde/a58c606c7ef0f36cb2a40e5f2c2c02e1 to your computer and use it in GitHub Desktop.
// inspired from: https://discuss.gradle.org/t/generated-eclipse-classpath-can-contain-duplicate-entries/15273/3
// Workaround to eliminate duplication eclipse classpath entries, it
// just takes the first entry if there are duplicates
eclipse {
classpath {
file {
whenMerged { cp ->
logger.lifecycle "Removing duplicate classpath entries from eclipse for project '${project.name}'"
def jrePath = "org.eclipse.jdt.launching.JRE_CONTAINER"
Map entryByPath = cp.entries.groupBy { entry ->
entry.path.startsWith(jrePath) ? jrePath : entry.path
}
entryByPath.each { key, values ->
if (values.size() > 1) {
def entry = values.first()
if (entry.kind == 'src') {
entry.includes = []
entry.excludes = []
}
int index = cp.entries.indexOf entry
logger.lifecycle "Removing ${values.collect { it.path }}"
cp.entries.removeAll values
logger.lifecycle "Adding ${entry.path}"
cp.entries.add index, entry
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment