Kotlin-dsl-samples: Can't run code/tests when setting properties of Action recievers in IntelliJ

Created on 27 Oct 2017  路  8Comments  路  Source: gradle/kotlin-dsl-samples

Using kotlin-dsl plugin and trying to use the run actions in IntelliJ does not work as expected, and fails with weird compiler errors when using the SAM-with-receiver plugin type.

The different run options for Gradle in IntelliJ make it a little bit more confusing. The issue is more prominent when trying to run JUnit 5 tests because Gradle, JUnit 5, and IntelliJ do not all play nice together (see https://github.com/gradle/gradle/issues/1037, and https://discuss.gradle.org/t/junit-5-gradle-and-intellij-publishing-test-events-for-tooling-api-consumers/21349).

Example showing compiler errors when running in IntelliJ

Expected Behavior

Expect compilation and tests to run correctly in IntelliJ.

Current Behavior

Compilation fails in IntelliJ, works fine in Gradle build.

Context

This impacts running tests with IntelliJ.

Workaround is to not use the Action configuration block and just call setters/apply after creating the object.

Steps to Reproduce (for bugs)

  • build.gradle.kts

    plugins {
      `kotlin-dsl`
    }
    tasks {
      "wrapper"(Wrapper::class) {
        gradleVersion = "4.3-rc-4"
      }
    }
    
  • src/main/kotlin/ExamplePlugin.kt

    import org.gradle.api.Plugin
    import org.gradle.api.Project
    
    open class ExamplePlugin : Plugin<Project> {
      override fun apply(project: Project) {
        project.tasks.create("hello") {
          description = "hello"
        }
        project.repositories.maven {
          name = "myRepo"
          setUrl("https://google.com")
        }
      }
    }
    
    fun main(args: Array<String>) {
      println("Dumb print for example")
    }
    

Your Environment

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

Gradle 4.3-rc-4

bug jetbrains kt-idea-plugin editing

Most helpful comment

I am definitely able to do this with Gradle 4.6 and IntelliJ Kotlin plugin 1.2.30 - closing

All 8 comments

Have you tried invalidating your IntelliJ cache and restarting?

Yes, still see same behavior.

This sounds like an issue to be opened on the kotlin youtrack. Would recommend including an example project.
@bamboo Which dev at JB would be the best person to make aware of this problem?

ping @bamboo or @eskatos to see if there is way for me to fix - this issue is annoying for plugin developers trying to use the kotlin-dsl plugin, and delegating run actions to Gradle doesn't work at all when using JUnit 5 because ther eis not integration (right now)

Possibly related to #476.

It looks like the IntelliJ run configuration doesn't have the sam-with-receiver compiler plugin configured.

This may be fixed with Kotlin 1.2.20 - I see the compiler plugins configured in the Kotlin Facets for my project, and I'm able to execute the tests in IntelliJ when using id("org.gradle.kotlin.kotlin-dsl") version "0.13.1" and Gradle 4.4.1 with Kotlin plugin Version: 1.2.20-release-IJ2017.3-1

I am definitely able to do this with Gradle 4.6 and IntelliJ Kotlin plugin 1.2.30 - closing

Was this page helpful?
0 / 5 - 0 ratings