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 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"


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 {

That worked. Thanks.

This is not working for
It DOES create an Artifact that you can build → build artifact
But it keeps on building the by default!

java.sourceCompatibility = JavaVersion.VERSION_11

tasks.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

This way you can solve it:


value and set do the same, just one returns the property for method call chaining. Whether war or bootWar task needs to be configured depends on whether it is the normal war plugin or the spring boot plugin that defines it.