gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

IDEA editing support is broken in 5.1 if gradle project root is not the same as IDEA project root #1308

Closed pacher closed 5 years ago

pacher commented 5 years ago

Steps to Reproduce (for bugs)

  1. Create empty project in IDEA
  2. File -> New -> Module from Existing Sources... and pick "hello-kotlin" sample project from somewhere on the file system
  3. Open build.gradle.kts file in IDEA

Current Behavior

Error "can not access script base class org.gradle.kotlin.dsl.KotlinBuildScript" IDEA can not resolve build script dependencies, everything red, so IDE editing of build scripts is unusable.

Building and running works, ".gradle" cache folder is created in module root (hello-kotlin folder) When build.gradle.kts file is opened in IDEA - the second ".gradle" cache folder is created in IDEA project root.

Context

It was working fine with gradle 5.0, the problem is in 5.1

The only possible project layout now is when root build script is directly in IDEA project root. Then those two ".gradle" cache folders collapse into one and everything works as expected. But even in layout like IDEA Project root \ Some other module root folder \ build.gradle.kts I get two cache folders and broken script resolution.

But it would be very nice to have several gradle projects (composite build) as different modules within one IDEA project

Your Environment

Everything fresh with latest updates possible Windows 10, jdk 11.0.1, gradle 5.1, IDEA 2018.3.2, kotlin 1.3.11

bamboo commented 5 years ago

Hi @pacher, thanks for the report.

Could you check if the following Gradle distribution fixes the issue for you?

    ./gradlew wrapper --gradle-distribution-url https://repo.gradle.org/gradle/kotlin-dsl-snapshots-local/gradle-kotlin-dsl-5.2-20190122225509+0000-all.zip
pacher commented 5 years ago

Hello @bamboo

I followed the steps to reproduce and the issue seems to be fixed. Yay! Thanks a lot. Script dependencies are resolved, syntax highlighting and code completion works.

There are still two .gradle cache folders though, is it normal and expected? Does not feel right. The second .gradle is created in IDEA project root folder when a *.gradle.kts file is opened in IDEA.

Thanks again for the fix and have a nice day ;-)

eskatos commented 5 years ago

Good, thanks for the feedback @pacher!

There are still two .gradle cache folders though, is it normal and expected? Does not feel right.

It is expected as the other "IDEA module" imported as a "IDE only included build" is actually its own build.

jmfayard commented 5 years ago

@eskatos Is it the same IDE support bug that affects Android Studio 3.2? https://github.com/jmfayard/bug-androidstudio-buildsrc https://issuetracker.google.com/issues/123032843