How to publish Spring Boot war file using Gradle 6.2+

When publishing from a Spring Boot 2.2.9 project using Gradle 6.6 I’m seeing this error:

java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Artifact my-app-1.1.0.war wasn't produced by this build.

The release notes for upgrading to version 6.2 state this:

Starting from Gradle 6.2, Gradle performs a sanity check before uploading, to make sure you don’t upload stale files (files produced by another build). This introduces a problem with Spring Boot applications which are uploaded using the components.java component:

A code snippet is provided for how to publish artifacts successfully when your artifact is a jar file. However, the artifact I want to publish is a war file created with ./gradew bootWar. I’ve tried making the following addition to my build.gradle:

configurations {
    [apiElements, runtimeElements].each {
        it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(war) }
        it.outgoing.artifact(bootWar)
    }
}

I’ve taken the suggestion and changed jar to war. However, I still experience the same error.

Any suggestions are appreciated. Thanks.

After bashing my keyboard a bit more I discovered that I may have been declaring my publications incorrectly. This Spring Boot documentation recommends something like this:

publishing {
    publications {
        webApp(MavenPublication){
            artifact bootWar
        }
    }
}

Whereas before I had:

publishing {
    publications {
        webApp(MavenPublication){
            from components.web
        }
    }
}

Having made this change the publishing now works. No further changes are requried despite what is mentioned in the Gradle 6.2 release notes.

Hi,
I am also using the bootWar and none of the above approaches is working for me.
I am using spring boot 2.3.2 and gradle 6.5.1
Ironically approach provided in the document works fine for bootJar but not for bootWar.
This is stopping me to upgrade spring boot and gradle both for quite some time now and any help is appreciated.
Thanks