How do I change the name of the war file when using Kotlin DSL?

I’m using Gradle 6.0.1 with Kotlin DSL. My build script uses the war plugin. How can I change the name of the war file built?

An older answer to a similar question (see https://discuss.gradle.org/t/how-do-i-change-the-name-of-the-war-file-being-built/9223/2) uses Groovy. I’m not sure how to achieve the same effect when using Kotlin.

Tried the following, but it did not work.

war {
    archiveFileName = "something.war"
}

Regards,
Manoj

You’ll need to be a bit more explicit in Kotlin. Get war from tasks and use the set method since archiveFileName is a Property<String>, not just a String.

tasks.war {
    archiveFileName.set("something.war")
}
1 Like

That worked. Thanks.

This is not working for
gradle-7.1.1
It DOES create an Artifact that you can build → build artifact
But it keeps on building the rootProject.name.war by default!

java.sourceCompatibility = JavaVersion.VERSION_11

tasks.war {
	archiveFileName.set("ROOT.war")
}

IntelliJ IDEA 2021.2 (Ultimate Edition)
Build #IU-212.4746.92, built on July 27, 2021
Runtime version: 11.0.11+9-b1504.13 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 4012M
Cores: 12
Non-Bundled Plugins: Batch Scripts Support (1.0.12)
Kotlin: 212-1.5.10-release-IJ4746.92