Open mkobit opened 7 years ago
Thanks for the well written report @mkobit! This looks like an IntelliJ issue to me, related to how delegated properties are handled. We need to find/fill an upstream issue. Ideally reproducing the faulty behavior with a simple Kotlin project not involving the Gradle Kotlin DSL.
One workaround would be to import org.gradle.kotlin.dsl.*
Good call with the star import (although I try not to use them) - definitely makes sense to report upstream as this is most likely an IntelliJ issue - I reported it here first due to it being the first and primary place I ran into it.
I'll hopefully report it tonight, but if not in the next few days and follow up on this issue.
Finally reported upstream at https://youtrack.jetbrains.com/issue/KT-22101 - the issue could use a friendlier description that isn't as much kotlin-dsl
but I did not write it yet.
From @big-guy
If we're going to ask people to use Kotlin in buildSrc, I think this is important.
The issue understates what happens in practice. The import is marked as unused, IntelliJ optimizes the imports and removes it, the build then fails. If you add the import back and save, IntelliJ removes it again. The only way to get it to not do this is to fiddle with Intellij defaults.
@big-guy, I don't recall this happening to me. Do you have Optimize imports on the fly
enabled? I believe it's not the default.
This also happens when using by registering
in a plugin which requires import org.gradle.kotlin.dsl.provideDelegate
or import import org.gradle.kotlin.dsl.*
as previously suggested.
When trying to use the domain object extension methods
getting
andcreating
in a plugin when usingkotlin-dsl
it leads to less than ideal behavior.Moving pictures speak a thousand words:
val taskName by tasks.getting
val taskName by tasks.creating
Expected Behavior
import
is not marked as unusedby creating
Current Behavior
import
is grayed out and removed by the Optimize Imports actionby creating
Context
Using
kotlin-dsl
in a plugin I am writingSteps to Reproduce (for bugs)
In
src/main/kotlin/ExampleKotlinDslPlugin.kt
Your Environment
Gradle 4.3-rc-2
IntelliJ IDEA 2017.2.5 Build #IU-172.4343.14, built on September 26, 2017 Licensed to Mike Kobit You have a perpetual fallback license for this version Subscription is active until September 5, 2018 JRE: 1.8.0_152-release-915-b12 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.10.0-37-generic