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 entry in generated .classpath file in Gradle >= 5.6 #10393

Closed
marcphilipp opened this issue Aug 29, 2019 · 10 comments
Closed

Duplicate entry in generated .classpath file in Gradle >= 5.6 #10393

marcphilipp opened this issue Aug 29, 2019 · 10 comments

Comments

@marcphilipp
Copy link
Member

@marcphilipp marcphilipp commented Aug 29, 2019

Expected Behavior

Given a consumer project with the following dependencies, the consumer/.classpath file generated by calling ./gradlew eclipse should only contain a single <classpathentry kind="src" path="/producer"/> entry.

dependencies {
    testImplementation(project(":producer"))
    testImplementation(project(":producer", configuration = "testArtifacts"))
}

Current Behavior

With Gradle 5.6 it contains two such entries and causes Eclipse to show a "duplicate classpath entry" error.

	<classpathentry kind="src" path="/producer"/>
	<classpathentry kind="src" path="/producer"/>

In Gradle 5.5 and below only a single entry is generated.

Context

The project is unusable in Eclipse until the duplicate entry is deleted manually.

Steps to Reproduce

  1. Clone https://github.com/marcphilipp/gradle-sandbox
  2. In eclipse-multiple-project-dependencies, run ./gradlew eclipse
  3. Inspect the generated consumer/.classpath file or open the project in Eclipse
@sbrannen
Copy link

@sbrannen sbrannen commented Aug 29, 2019

Thanks for investigating this!

I'm looking forward to the JUnit 5 projects working in Eclipse again (without having to manually delete those duplicate classpath entries). 😉

@marcphilipp
Copy link
Member Author

@marcphilipp marcphilipp commented Aug 29, 2019

Possibly related to #9405.

@marcphilipp
Copy link
Member Author

@marcphilipp marcphilipp commented Aug 29, 2019

Workaround:

import org.gradle.plugins.ide.eclipse.model.Classpath

eclipse.classpath.file {
    whenMerged(Action<Classpath> {
        entries = entries.distinctBy {
            if (it is org.gradle.plugins.ide.eclipse.model.ProjectDependency)
                it.path
            else
                it
        }
    })
}

@ryanmkurtz
Copy link

@ryanmkurtz ryanmkurtz commented Aug 29, 2019

We are seeing duplicate project dependencies ending up in the generated .classpath files with 5.6 and 5.6.1 in Ghidra as well.

@sbrannen
Copy link

@sbrannen sbrannen commented Aug 29, 2019

FYI: to get the above Kotlin-based workaround to work, you'll need the following.

import org.gradle.plugins.ide.eclipse.model.Classpath

sbrannen added a commit to junit-team/junit5 that referenced this issue Aug 29, 2019
@sbrannen
Copy link

@sbrannen sbrannen commented Aug 29, 2019

I can confirm that the provided workaround solves the issue for the time being. See junit-team/junit5@3e9565a.

Thanks, @marcphilipp!

@ryanmkurtz
Copy link

@ryanmkurtz ryanmkurtz commented Aug 29, 2019

Would you mind posting an equivalent groovy workaround?

@sbrannen
Copy link

@sbrannen sbrannen commented Aug 29, 2019

Would you mind posting an equivalent groovy workaround?

I don't have one handy, but the following documentation should be helpful.

https://docs.gradle.org/current/userguide/eclipse_plugin.html#sec:eclipse_modify_domain_objects

@sbrannen
Copy link

@sbrannen sbrannen commented Aug 29, 2019

And the customization I wrote here might prove useful as well for the Groovy syntax: https://github.com/spring-projects/spring-framework/blob/8d86a861a1eff13dd1abe14829e4213200509300/gradle/ide.gradle#L50-L57

@marcphilipp
Copy link
Member Author

@marcphilipp marcphilipp commented Aug 29, 2019

@ryanmkurtz Here's a Groovy version:

eclipse.classpath.file {
    whenMerged {
        entries.unique(true) {
            (it instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency) ? it.path : it
        }
    }
}

@donat donat self-assigned this Aug 30, 2019
@big-guy big-guy added this to the 5.6.2 milestone Sep 3, 2019
@ghale ghale closed this as completed Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants