我刚刚将我的 Gradle 升级到 5.x,当我尝试同步我的库项目时遇到了一个新错误。此错误来自发布 block ,我需要将我的库发布到本地 Maven。
这就是我以前对 Gradle 4 所做的,它工作得很好:
apply plugin: 'maven-publish'
publishing {
publications {
library(MavenPublication) {
groupId = 'myGroupId'
artifactId = 'myArtifactId'
version = android.defaultConfig.versionName
artifact bundleDebugAar
}
}
}
使用 Gradle 5,我现在在同步 gradle 项目时遇到关于 Artifact 的错误:
ERROR: Could not get unknown property 'bundleDebugAar' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
当我删除 Artifact 行时,我可以同步项目,但是当我尝试 publishToMavenLocal 时,我的构建失败了:
Execution failed for task ':mypackage:generatePomFileForLibraryPublication'.
No value has been specified for this provider.
我查看了 gradle 升级指南,但我不知道如何解决我的问题:https://docs.gradle.org/5.0/userguide/upgrading_version_4.html#rel5.0:pom_compile_runtime_separation
有人能告诉我这个新版本有什么我没有看到的变化吗?谢谢。
最佳答案
对于 gradle 4.8+,您必须将 publishing{}
block 包含在 project.afterEvaluate
project.afterEvaluate {
publishing {
publications {
aar(MavenPublication) {
//...
artifact bundleReleaseAar
}
}
}
}
您可以找到 official doc here :
Prior to Gradle 4.8, the publishing {} block was implicitly treated as if all the logic inside it was executed after the project was evaluated. This was confusing, because it was the only block that behaved that way. As part of the stabilization effort in Gradle 4.8, we are deprecating this behavior and asking all users to migrate their build.
关于android - Gradle 5.x - 将我的库发布到 Maven Local 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55747082/