0

I have a Kotlin Multiplatform project (1.7.10), with multiple subprojects, using Gradle 7.4.2. When running Gradle tasks I regularly get an error message from the Kotlin Gradle plugin:

* What went wrong:
Execution failed for task ':modules:web-map:publicPackageJson'.
> Error while evaluating property 'externalDependencies$kotlin_gradle_plugin' of task ':modules:web-map:publicPackageJson'
   > Projects must be configuring

The error will not go away, unless I somehow force the project to 'refresh'. So I can temporarily work around this by making an incidental edit to the root build.gradle.kts, for example changing

// $projectRoot/build.gradle.kts

println("annoying bug")

into

// $projectRoot/build.gradle.kts

//println("annoying bug")

This minor change somehow forces the Kotlin plugin to 'refresh', and I can then run the Gradle task again.... until the next time. The bug is very quick to re-occur.

There are several bug tickets opened, but they have been awaiting resolution for months.

However this bug is incredibly frustrating, so I would like to have a work around.

I have already tried

  • disable Gradle caching
  • disable Gradle parallelization
  • force the Kotlin Gradle tasks to always run, by adding a 'cache busting' Gradle task input to all tasks
  • creating a Gradle task that will automatically edit build.gradle.kts before all tasks, to automate forcing the refresh.

Unfortunately nothing worked consistently.

An example project is available here: https://youtrack.jetbrains.com/issue/KT-52647/KJS-Gradle-Make-Projects-must-be-configuring-a-warning#focus=Comments-27-6195302.0-0

aSemy
  • 5,485
  • 2
  • 25
  • 51

1 Answers1

0

I have created a hack elegant temporary workaround.

I created a Gradle task, projectsMustBeConfiguringBuster, that will make an incidental edit to a Gradle script, and registered that task as a finalizer task of all other tasks. This somehow resets the Kotlin plugin so it thinks the project is 'configuring'.

To try and keep things clean, I created a new Gradle script, kt52647.gradle.kts, which I apply in the root build.gradle.kts. If you wanted, you could add this file to .gitignore, or commit it but then tell Git to ignore any future changes.

// $projectRoot/build.gradle.kts

// ... other build settings ...

apply(from = "$projectDir/kt52647.gradle.kts")
// $projectRoot/kt52647.gradle.kts

val projectsMustBeConfiguringBuster by tasks.registering {
  outputs.upToDateWhen { false }
  val buildFile = rootProject.layout.projectDirectory.file("kt52647.gradle.kts").asFile
  doLast {
    logger.warn("Applying 'Projects must be configuring' workaround - https://youtrack.jetbrains.com/issue/KT-52647")

    val newLines = buildFile.readText().lines().joinToString("\n") { line ->
      if (line.startsWith("// projects must be configuring buster")) {
        "// projects must be configuring buster ${System.currentTimeMillis()}"
      } else {
        line
      }
    }

    buildFile.writeText(newLines)
  }
}

allprojects {
  tasks
    .matching { it.name != projectsMustBeConfiguringBuster.name }
    .configureEach {
      finalizedBy(
        rootProject.tasks.matching { it.name == projectsMustBeConfiguringBuster.name }
      )
    }
}


// projects must be configuring buster 1664920329388
// ^ this line will be edited by projectsMustBeConfiguringBuster

I can now repeatedly run ./gradlew assemble and I don't get an error.

If I comment out finalizedBy(...) I encounter the "Projects must be configuring" bug on the second assemble run.

aSemy
  • 5,485
  • 2
  • 25
  • 51