Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate source path entries in classpath #28

Open
hacki11 opened this issue Jul 27, 2018 · 0 comments
Open

Duplicate source path entries in classpath #28

hacki11 opened this issue Jul 27, 2018 · 0 comments

Comments

@hacki11
Copy link

hacki11 commented Jul 27, 2018

hi!

i'm experiencing an issue having build config with eclipse plugin activated.
Sourcefolder src/main/java and src/main/test will be duplicate in generated .classpath file. this results in a BuildPathError within eclipse.

.classpath without BuildConfig plugin activated after build task:

<classpath>
    <classpathentry path="bin" kind="output"/>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/test/java"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
</classpath>

.classpath with BuildConfig activated after build task:

<classpath>
	<classpathentry kind="src" path="src/main/java"/>
	<classpathentry kind="src" path="src/test/java"/>
	<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
	<classpathentry kind="output" path="bin/default"/>
	<classpathentry output="bin/main" kind="src" path="src/main/java">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry output="bin/test" kind="src" path="src/test/java">
		<attributes>
			<attribute name="gradle_scope" value="test"/>
			<attribute name="gradle_used_by_scope" value="test"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
</classpath>

Eclipse is angry having two build path entries (src/main/java and test).

my workaround is eliminating the duplicate entries:

// this eliminates duplicate entries in .classpath
eclipse {
    classpath {
        file.whenMerged { cp ->
            logger.lifecycle "Removing duplicate classpath entries from eclipse for project '${project.name}'"

            Map entryByPath = cp.entries.groupBy { entry -> 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
                }
            }
        }
    }
}

BuildConfigPlugin 1.1.8
Gradle 4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant