Weird error on attempted upgrade to Gradle 6.1.1

We have the following working line of build script running on Gradle 5.2.1:

version = object {
    val value : String by lazy {
        VersionBuilderPlugin.versionFromGitTag()
    }
    override fun toString() : String = value
}

On attempting to run the build on Gradle 6.1.1, we get an error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/tester/Documents/gradle-plugins-common/build.gradle.kts' line: 18

* What went wrong:
'void Build_gradle$1.<init>(Build_gradle)'

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.NoSuchMethodError: 'void Build_gradle$1.<init>(Build_gradle)'
        at Build_gradle.<init>(build.gradle.kts:18)
        at Program.execute(Unknown Source)

What changed here, and what’s the fix?

Hi Trejkaz,

It’s hard to say without a little more context around the offending line but it does look like a Kotlin compiler bug we have seen recently.

Could you provide more context around the offending line, in particular, if it’s part of a lambda expression and/or there are lambda expressions close to the offending line?

Cheers!

The whole build script, with just our packages renamed:

import com.acme.gradle.plugins.common.checkstrings.CheckStrings
import com.acme.gradle.plugins.common.config.VersionBuilderPlugin

plugins {
    `java-gradle-plugin`

    id("pl.droidsonroids.jacoco.testkit") version "1.0.3"
}

apply(from = "common-build.gradle.kts")
apply<com.acme.gradle.plugins.common.CommonPlugin>()

group = "com.acme.gradle.plugins"
version = object {
    val value : String by lazy {
        VersionBuilderPlugin.versionFromGitTag()
    }
    override fun toString() : String = value
}

gradlePlugin {
    plugins {
        register("common") {
            id = "com.acme.gradle.plugins.common"
            implementationClass = "com.acme.gradle.plugins.common.CommonPlugin"
        }
    }
}

var projectTitle : String by project.extra
projectTitle = "Gradle Plugin Commons"

tasks.named<CheckStrings>("checkStringsMain") {
    exclude("**/META-INF/gradle-plugins/*.properties")
}

configure<PublishingExtension> {
    val artifactory_contextUrl : String by project
    repositories.getByName<MavenArtifactRepository>("snapshot").url = uri("${artifactory_contextUrl}/plugins-snapshot-local")
    repositories.getByName<MavenArtifactRepository>("release").url = uri("${artifactory_contextUrl}/plugins-release-local")
}

tasks.withType<Test> {
    systemProperty("apple.awt.UIElement", "true")
}

Thanks, Trejkaz.

Unfortunately I was unable to reproduce the problem so far. Would it be possible for you to try to provide a standalone reproducer?

The real version also takes a string parameter, which might be the key difference… once I remove that, it somehow works.

If you need more than that, I’m about 10% of the way towards a standalone repro but there’s a lot of stuff in the build that I still have to fish through.

I at least reduced the surface area of the build script:

import com.acme.gradle.plugins.common.VersionBuilderPlugin

plugins {
    `java-gradle-plugin`
}

apply(from = "common-build.gradle.kts")

version = object {
    val value : String by lazy {
        VersionBuilderPlugin.gitTagVersion(project.getProjectDir().getAbsolutePath())
//        VersionBuilderPlugin.gitTagVersion()
    }
    override fun toString() : String = value
}


Even smaller, and no longer even calls our own class:

version = object {
    val value : String by lazy {
        projectDir.toString()
    }
    override fun toString() : String = value
}

Actually so that’s a standalone reproduction now. The only files I have other than the Gradle wrapper is that 6 line build script and a one-line settings.gradle.kts setting the name of the project.

Even smaller repro:

version = object {
    val value by lazy { projectDir }
}