Publish war file from buildSrc in Gradle 7.1

Hi,

I’d like to request some help with how to publish (using the maven-publish plugin) a war file produced using the org.gradle.war plugin, in particular when the rules are defined from Kotlin code in a buildSrc plugin. Information about how to do this seems to be surprisingly scarce. I have seen several sources suggesting to publish from components.web as software component (for example here). It does try to publish the right file, but Gradle complains that the file is not produced by the build. Except it is produced by the build task, just not the publish task. I suspect most of the information out there is only applicable to 6.x (if at all), not 7.x.

Here is the relevant buildSrc code that I have:

internal fun Project.configureWarFilePublication() {
    configure<PublishingExtension> {
        publications {
            create("nexus", MavenPublication::class.java) {
                from(components.getByName("web"))
                pom {
                    scm {
                        connection.set(property("com.example.scm.connection"))
                        developerConnection.set(property("com.example.scm.connection.developer"))
                    }
                }
            }
        }
    }
}

class WarPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        project.plugins.apply("org.gradle.war")
        project.configureExecutable()  // sets up various dependency constraints, more plugins etc
        project.configureWarFilePublication()

        // ...
    }
}

When I run ./gradlew publish, I get:

* What went wrong:
Execution failed for task ':reaktor:publishNexusPublicationToMavenRepository'.
> Failed to publish publication 'nexus' to repository 'maven'
   > Artifact reaktor-0.1-SNAPSHOT.war wasn't produced by this build.

I’ve examined WebApplication.getUsages().getArtifacts() and it appears to reference the right path, and that file is produced by ./gradlew build, but not by ./gradlew publish. It would appear that some internal dependency is missing or something is wrong with the build order, but I’m at a loss what to do about it.

My version info:

% ../gradlew --version

------------------------------------------------------------
Gradle 7.1
------------------------------------------------------------

Build time:   2021-06-14 14:47:26 UTC
Revision:     989ccc9952b140ee6ab88870e8a12f1b2998369e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.11 (Ubuntu 11.0.11+9-Ubuntu-0ubuntu2)
OS:           Linux 5.11.0-37-generic amd64