Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

KT-22101 IntellIj suggests unused import for org.gradle.kotlin.dsl.getValue when using kotlin-dsl and doesn't suggest import for creating #564

Open
mkobit opened this issue Oct 20, 2017 · 5 comments

Comments

@mkobit
Copy link
Contributor

mkobit commented Oct 20, 2017

When trying to use the domain object extension methods getting and creating in a plugin when using kotlin-dsl it leads to less than ideal behavior.

Moving pictures speak a thousand words:

  • val taskName by tasks.getting

    Unused import when using by getting

  • val taskName by tasks.creating

    Unused import when using by creating

Expected Behavior

  • import is not marked as unused
  • no autocomplete suggested for by creating

Current Behavior

  • the import is grayed out and removed by the Optimize Imports action
  • no suggestion for autocomplete when using by creating

Context

Using kotlin-dsl in a plugin I am writing

Steps to Reproduce (for bugs)

plugins {
  `kotlin-dsl`
  `java-library`
  `java-gradle-plugin`
}

In src/main/kotlin/ExampleKotlinDslPlugin.kt

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.creating

open class ExampleKotlinDslPlugin : Plugin<Project> {
  override fun apply(project: Project) {
    project.run {
      val myTask by tasks.creating
    }
  }
}

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

@eskatos
Copy link
Member

eskatos commented Oct 31, 2017

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.*

@mkobit
Copy link
Contributor Author

mkobit commented Oct 31, 2017

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.

@mkobit
Copy link
Contributor Author

mkobit commented Jan 2, 2018

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.

@eskatos eskatos changed the title IntellIj suggests unused import for org.gradle.kotlin.dsl.getValue when using kotlin-dsl and doesn't suggest import for creating KT-22101 IntellIj suggests unused import for org.gradle.kotlin.dsl.getValue when using kotlin-dsl and doesn't suggest import for creating Jan 4, 2018
@eskatos eskatos added this to the 1.0.0 milestone Jan 19, 2018
@eskatos eskatos modified the milestones: 1.0.0, 1.1.0 May 22, 2018
@eskatos
Copy link
Member

eskatos commented Jun 8, 2018

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.

image

@mkobit
Copy link
Contributor Author

mkobit commented Aug 15, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants