Gradle Kotlin DSL:从依赖项中提取内容

时间:2019-02-22 19:00:00

标签: java gradle groovy kotlin gradle-kotlin-dsl

如何将以下代码段(基于Peter Niederwieser的代码段)转换为Kotlin?

configurations {
    assets
}
dependencies {
    assets 'somegroup:someArtifact:someVersion'
}
task extractApi(type: Sync) {
    dependsOn configurations.assets

    from { // use of closure defers evaluation until execution time
        configurations.assets.collect { zipTree(it) }
    }
    into "$buildDir/assets/"
}

1 个答案:

答案 0 :(得分:1)

我没有Kotlin DSL的经验,但是显然extractApi任务可以重写为

val assets by configurations.creating

dependencies {
    assets("somegroup", "someArtifact", "someVersion")
}

tasks {
    val extractApi by creating(Sync::class) {
        dependsOn(assets)

        from(assets.map {
            zipTree(it)
        })

        into("$buildDir/api/")
    }
}