vanniktech / gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
https://vanniktech.github.io/gradle-maven-publish-plugin
Apache License 2.0
1.26k stars 116 forks source link

DefaultPluginCollection#all(Action) on KotlinMultiplatformPluginWrapper cannot be executed in the current context #813

Open Nek-12 opened 1 month ago

Nek-12 commented 1 month ago
An exception occurred applying plugin request [id: 'com.vanniktech.maven.publish', version: '0.29.0']
10 actionable tasks: 10 executed
> Failed to apply plugin 'com.vanniktech.maven.publish'.
Configuration cache entry stored.
   > DefaultPluginCollection#all(Action) on [org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper@[52](https://github.com/respawn-app/ApiResult/actions/runs/10096579651/job/27919446084#step:7:53)318e28] cannot be executed in the current context.

I have configured the plugin to be configured in the root project for all subprojects:

plugins.withType<MavenPublishPlugin>().configureEach {
    the<MavenPublishBaseExtension>().apply {
        val isReleaseBuild = properties["release"]?.toString().toBoolean()
        publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, false)
        if (isReleaseBuild) signAllPublications()
        coordinates(Config.artifactId, name, Config.version(isReleaseBuild))
        // ... 
    }
}

I used this trick successfully to configure the compose compiler plugin (if it is applied) for each project module, however it seems that the publishing plugin does some illegal stuff in the signAllPublications() that cannot be executed in the plugin configuration block. If I remove the plugins.configureEach clause, then the extension is not configured at all.

Is there any hack I can shove in or other way to configure the publishing plugin once and then release all subprojects that have the publishing plugin applied with a single task? Not all projects have to be published.

maartenvgpersgroep commented 1 week ago

@Nek-12 Did you come up with a solution for this? I do something very similar and I'm running into the same issue. It's happening since version 0.29.0, not with 0.28.0 or earlier.

My use case: in my build config I have an utility function to configure publishing for all subprojects.

fun Project.configurePublishing() {
  plugins.apply("com.vanniktech.maven.publish")

  publishing {
    repositories {
      maven(url = "...")
    }
  }

  mavenPublishing {
    pom { coordinates(LibConfig.groupId, project.name, LibConfig.versionName) }
  }
}

It is then used like this:

subprojects {
    configurePublishing()
}
Nek-12 commented 1 week ago

I did, a workaround that worked was to configure after evaluation: https://github.com/respawn-app/FlowMVI/blob/50676f0291c05ee811d6594da6dc2ecc8cf2d319/build.gradle.kts#L44