我有一个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=release
或gradle uploadArchives -PbuildType=snapshot
如果-PbuildType=
是release
或snapshot
之外的其他任何东西,我将使构建失败,那部分工作正常。
但是,当我执行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
,并将其部署发布。