gpt4 book ai didi

java - 如何使 uploadArchives 依赖于另一个任务?

转载 作者:搜寻专家 更新时间:2023-11-01 07:57:22 24 4
gpt4 key购买 nike

我的 build.gradle 中有以下内容:

afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
pom.packaging = "aar"
pom.groupId = project.CORE_GROUP
pom.version = project.CORE_VERSION_NAME

repository(url: "scp://" + project.CORE_MAVEN_URL) {
authentication(userName: project.uploadUsername, privateKey: project.uploadKeyFile)
}
}
}
}
}

我希望它依赖于以下任务:

task checkProperties << {
if (!project.hasProperty('uploadUsername')) {
throw new RuntimeException("Couldn't find uploadUsername property. Did you forget to specify it in ~/.gradle/gradle.properties?")
} else if (!project.hasProperty('uploadKeyFile')) {
throw new RuntimeException("Couldn't find uploadKeyFile property. Did you forget to specify it in ~/.gradle/gradle.properties?")
}
}

我怎样才能做到这一点?如果我写以下内容:

afterEvaluate { project ->
uploadArchives(dependsOn: checkProperties) {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
pom.packaging = "aar"
pom.groupId = project.CORE_GROUP
pom.version = project.CORE_VERSION_NAME

repository(url: "scp://" + project.CORE_MAVEN_URL) {
authentication(userName: project.uploadUsername, privateKey: project.uploadKeyFile)
}
}
}
}
}

然后我得到以下错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/scottjohnson/Source/core-android/core/build.gradle' line: 61

* What went wrong:
A problem occurred configuring project ':core'.
> org.gradle.api.internal.MissingMethodException: Could not find method mavenDeployer() for arguments [build_42edqo477lbj5geoh0e3gdkj7q$_run_closure6_closure9_closure10_closure11@30b8afce] on repository container.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.68 secs

顺便说一句,我想这样做的原因是现在,如果我只是将检查属性的代码放入 uploadArchives 任务中,那么即使我运行 ./gradlew clean build,它会检查属性(我不想在我的构建服务器上发生这种情况,因为它没有实际上传文件的权限)。因此,仅当执行 uploadArchives 任务时才检查属性的方法也是可以接受的。

最佳答案

关于您的错误消息,您可能会错过将 maven 插件应用到您的 build.gradle 文件(应用插件:'maven')。

参见:https://discuss.gradle.org/t/configure-mavendeployer-programmatically/16956/2

关于java - 如何使 uploadArchives 依赖于另一个任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26344925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com