You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle 8.x Kotlin DSL中如何设置Manifest属性?

Gradle 8.x中Kotlin DSL设置Manifest主类的替代方案

Gradle 8.0+对Kotlin DSL的Manifest API做了调整,移除了原有的下标操作符([])赋值方式,因此你需要改用以下两种方式之一来设置Main-Class属性:

方案1:使用attributes()方法(推荐)

直接传入键值对来设置Manifest属性,代码更简洁:

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

方案2:使用put()方法

通过attributes.put()显式添加属性,和原逻辑语义一致:

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

这两种方式都能解决"No set method providing array access"的报错,同时兼容Gradle 8.x的API规范。

内容的提问来源于stack exchange,提问作者Yamin Siahmargooei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 00:39:57