如何在Gradle中基于Kotlin DSL的多项目中禁用distZip

时间:2018-10-16 13:55:54

标签: gradle build kotlin gradle-kotlin-dsl

我已经使用Kotlin DSL建立了Gradle多项目构建。这是build.gradle.kts的根目录:

plugins {
    kotlin("jvm") version "1.2.70" apply false
}

allprojects {
    repositories {
      mavenCentral()
    }
}

subprojects {
    version = "1.0"
}

这是我的子项目中的sub/build.gradle.kts

plugins {
    application
    kotlin("jvm")
}

application {
    mainClassName = "me.package.MainKt"
}

dependencies {
    compile(kotlin("stdlib"))
    compile("io.github.microutils:kotlin-logging:1.6.10")
    compile("ch.qos.logback:logback-classic:1.2.3")
}

当我运行$ gradle build时,application插件在sub/build/distribution中创建了一个发行版。

我不需要zip发行版,也不需要tar发行版中的版本号。两者在常规build.gradle中都应该是微不足道的,例如:

distZip.enabled = false
distTar.archiveName = "${project.name}.tar" 

无论我尝试使用Kotlin DSL多少,都会得到Unresolved reference: distZip。如何处理distZipdistTar任务?

1 个答案:

答案 0 :(得分:2)

What you need is:

val distZip by tasks
distZip.enabled = false
val distTar by tasks
distTar.archiveName = "${project.name}.tar" 

or:

tasks.getByName<Zip>("distZip").enabled = false
tasks.getByName<Tar>("distTar").archiveName = "${project.name}.tar"