buildship icon indicating copy to clipboard operation
buildship copied to clipboard

Classpath container include 'build/main' entries when using Kotlin 1.8.20

Open philwebb opened this issue 2 years ago • 8 comments

Expected Behavior

When importing a project that has the Kotlin Gradle plugin the eclipse classpath should not include entries for the build/classes/java and build/classes/kotlin. Having these additional entries makes Eclipse hard to use. For example, searching for a type will find both the source code and the previously built .class file.

Current Behavior

When using Kotlin 1.8.20 additional classpath entries are added. Downgrading to Kotlin 1.8.10 fixes the issue.

Context

Originally discovered in https://github.com/spring-projects/spring-boot/issues/35101

Steps to Reproduce

https://github.com/philwebb/kotlin-buildship-classpath-bug

Your Environment

Details are in the reproducer project readme

philwebb avatar Apr 24 '23 18:04 philwebb

The org.jetbrains.kotlin.jvm plugin contributes the build directories to the testCompileClasspath. Buildship puts both the production and the test dependencies to the same classpath, that's why you see it. There are a couple of workarounds you can do:

  • Remove offending dependencies by modifying eclipse.classpath.plusConfigurations and/or eclipse.classpath.minusConfigurations (given your test and production code are in different subprojects)
  • adjust the eclipse classpath via the eclipse.classpath.file.whenMerged {} callback.

donat avatar Apr 25 '23 15:04 donat

Thanks @donat! This commit did the trick for us https://github.com/spring-projects/spring-boot/commit/13d00d85e0f1af49356ea19fe7ec09cce74975a3

philwebb avatar Apr 25 '23 20:04 philwebb

@donat I think we have a similar problem with Spring Boot's Gradle Plugin for ahead-of-time processing. Is this something that you can fix in Buildship? My expectation was that it would "deduplicate" build/classes/java and bin/main, only keeping the latter as it's the Eclipse-specific equivalent of the former.

wilkinsona avatar Apr 25 '23 20:04 wilkinsona

See also #1236 (probably would be fixed the same way - de-deuplication of classpath entries).

dsyer avatar Apr 26 '23 13:04 dsyer

Kotlin 1.9.0 will restore the behaviour in 1.8.10

sellmair avatar May 05 '23 13:05 sellmair

Unfortunately, we detected that reverting the behaviour back to 1.8.10 clashes with a workaround applied for: https://youtrack.jetbrains.com/issue/KT-58280/org.jetbrains.kotlin.jvm-Gradle-plugin-contributes-build-directories-to-the-test-compile-classpath

Which relates to https://github.com/gradle/gradle/issues/23932

I therefore need to revoke the previous message. We are aiming to restore behaviour in 1.9, but the first attempt failed and the initial beta is right around the corner already.

cc @Tapchicoma

sellmair avatar May 11 '23 14:05 sellmair

AIUI, the NBT Gradle Plugin also configures things in such a way that build/main entries end up on the classpath when using Buildship. IMO, it would be better to fix this at source in Buildship rather than multiple plugins all working around the problem.

wilkinsona avatar May 11 '23 16:05 wilkinsona

For now, the change in KGP was reverted and will likely be shipped in 1.9.0-Beta

sellmair avatar May 16 '23 11:05 sellmair