Kotling Gradle构建检查仅在任务内部进行变量

时间:2018-07-20 04:11:29

标签: maven gradle kotlin

我有一个Kotlin库,打算将其部署到私有Maven存储库中,这是我的发布任务:

tasks {
"uploadArchives"(Upload::class) {
    if(project.hasProperty("buildType")) {
        if( (project.property("buildType")!!.toString().equals("snapshot", true)) ){
            version = "$version-SNAPSHOT"
        } else if( (project.property("buildType")!!.toString().equals("release", true)) ) {
            //do nothing, this deploys to release
        } else {
            error("Invalid release type")
        }
    } else {
        error("Must specify a release type")
    }
    repositories {
        withConvention(MavenRepositoryHandlerConvention::class) {
            mavenDeployer {
                withGroovyBuilder {
                    "repository"("url" to uri("http://maven_host/repository/maven-releases/")) {
                        "authentication"("userName" to "myUserName", "password" to "myPassword")
                    }
                    "snapshotRepository"("url" to uri("http://maven_host/repository/maven-snapshots/")) {
                        "authentication"("userName" to "myUserName", "password" to "myPassword")
                    }
                }
            }
        }
    }
}

}

基本思想是我将其称为gradle uploadArchives -PbuildType=releasegradle uploadArchives -PbuildType=snapshot

如果-PbuildType=releasesnapshot之外的其他任何东西,我将使构建失败,那部分工作正常。

但是,当我执行gradle build时,构建失败是因为我没有指定buildType

* What went wrong:

A problem occurred configuring project ':rocket'.

> Must specify a release type

在运行buildType任务时,如何告诉Gradle仅检查uploadArchives变量?如果我删除了最后一个else

else {
    error("Must specify a release type")
}

某人可以运行uploadArchives,并将其部署发布。

0 个答案:

没有答案