How to set Manifest's attributes in Gradle 8.x and Kotlin DSL

461 Views Asked by At

Recently I created a project in Kotlin that used Kotlin DSL for the build.gradle.kts file and I used Gradle 7.4.2 but after upgrading to 8.0.2 I'm unable to set attributes for manifest. I did that to set the main class for creating the jar file.
A portion of my build.gradle.kts:

tasks.jar {
    manifest {
        attributes["Main-Class"] = "io.github.yamin8000.twitterscrapper.MainKt"
    }
    configurations["compileClasspath"].forEach { file: File ->
        from(zipTree(file.absoluteFile))
    }
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

IDE complains that No set method providing array access for line 3.
So what's the alternative to array access which looks unavailable in Gradle 8.x.?

1

There are 1 best solutions below

0
natronite On

It's an old question but maybe this could help someone.

manifest.attributes is an object of type Attributes. What you should do is:

manifest {
    attributes("Main-Class" to "io.github.yamin8000.twitterscrapper.MainKt")
}