eclipse / buildship

The Eclipse Plug-ins for Gradle project.
530 stars 170 forks source link

Problem with Gradle-Build, if testImplementation testFixtures and implementation is used #1206

Closed cherni78 closed 1 month ago

cherni78 commented 1 year ago

Expected Behavior

Eclipse compiles if I use testImplementation testFixtures and implementation of the same project as it does with Gradle 7.4.2!

Current Behavior

As soon as I need the above listed configurations, Eclipse doesn't compile successful.

Context

A minimal setup to reproduce is present here: https://github.com/BisonSchweizAG/gradleproblem/tree/main

Steps to Reproduce

Clone above project, import into Eclipse --> will not compile! Build on command line will work. Remove needed line testImplementation testFixtures(project(':projectA')) from build.gradle --> Eclipse compiles, command line build won't!

Your Environment

Eclipse:
Version: 2022-06 (4.24.0)
Build id: 20220609-1112

Gradle: 7.5.1

Buildship: 3.1.6.v20220511-1359
flozano commented 1 year ago

Reproduced here. We've been hit very hard by this issue; when refreshing gradle in eclipse everything's broken.

flozano commented 1 year ago

BTW: it still happens with SNAPSHOT version of buildship:

Eclipse Buildship   Buildship, Eclipse Plug-ins for Gradle  3.1.7.v20220902-0443-s  org.eclipse.buildship
Eclipse Buildship   Buildship, Eclipse Plug-ins for Gradle  3.1.7.v20220902-0443-s  org.eclipse.buildship.oomph

and gradle 7.5.1.

I just confirmed that downgrading to gradle 7.4.2 fixes the issue and that 7.5 reproduces the issue also.

cherni78 commented 1 year ago

Still the same problem with the actual version 7.6.

flozano commented 1 year ago

still happens in eclipse 2022-12 with gradle 7.6...

flozano commented 1 year ago

Still happens with latest snapshot of buildship (3.1.7.v20221111-0445-s)

flozano commented 1 year ago

is there any workaround other than downgrading gradle?

cherni78 commented 1 year ago

Unfortunately, no! Respectively no one that I would know.

stefanrybacki commented 1 year ago

seems related to https://github.com/gradle/gradle/issues/21853

cherni78 commented 1 year ago

Yes, it is related! The workaround mentioned there works for me too.


eclipse.classpath {
    file.whenMerged { classpath ->
        classpath.entries.findAll { entry -> entry instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency && entry.entryAttributes.test }
            .each { it.entryAttributes['test'] = 'false' }
    }
}
filipe-amberflo-io commented 1 year ago

This is happening to me to. Gradle 8.1, Eclipse JDTLS 1.23.

The workaround above works. Here it is in Kotlin.

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

eclipse.classpath.file {
    whenMerged(Action<Classpath> { ->
        entries.filter { entry -> entry is ProjectDependency && entry.entryAttributes.containsKey("test") }
            .forEach { (it as ProjectDependency).entryAttributes["test"] = "false" }
    })
}
mr1chter commented 1 year ago

When generating the eclipse project files with the eclipse plugin, aka ./gradlew eclipse the files get generated just fine. So afaict this is more of a buildship issue, even if it just uses gradle classes.

But for me, this is just the next link in a long chain of issues with the gradle <-> eclipse connection. I'm tired. If you let this issue lying around, it'll solve itself because no one is using eclipse or gradle anymore.

E.g.: you can only do this workaround if you do it after the java plugin gets applied, because existing configs get mercilessly overwritten (https://github.com/gradle/gradle/blob/master/subprojects/ide/src/main/java/org/gradle/plugins/ide/eclipse/EclipsePlugin.java#L240) and while not recommended, you can do apply plugin: 'eclipse', then do your config, and then apply the java plugin (maybe because you do blanket-configs for all modules).

donat commented 5 months ago

Fixed in https://github.com/gradle/gradle/pull/28556

nlisker commented 1 month ago

Should be closed as fixed then?