android - Gradle 5.x - 将我的库发布到 Maven Local 时出错

标签 android maven gradle build.gradle

我刚刚将我的 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/

相关文章:

android - Here 移动 SDK PositionSimulator

android - 使用 keytool 以非交互方式生成 key

class - 给出了 Maven 依赖关系,但执行时仍然找不到一个类

shell - Jenkins war 部署

java - `gradle run` 没有 gradle

java - 为 Java Spring Boot Gradle 项目构建 Heroku Procfile

android 是否可以写保护我使用 StorageAccessFramework 创建的纯文本文件?

android - 2D opengl 游戏中多屏幕支持的提示?

java - Maven: Artifact 的权限被拒绝

android - 从 Gradle 构建中排除临时 Realm 文件