No longer able to use bundleReleaseAar in MavenPublication

前端 未结 3 893
暖寄归人
暖寄归人 2021-01-11 22:44

After upgrading Gradle to 5.1.1, I found that I\'m unable to add bundleReleaseAar as an artifact to my MavenPublication. Here\'s the relevant snippet of my buil

相关标签:
3条回答
  • 2021-01-11 23:26

    I solved it by calling the artifact function into the afterEvaluate closure, the issue is that the artifact function does not handle all the configuration lazily

    publishing {
       publications {
          aar(MavenPublication) {
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId
            afterEvaluate {
               artifact bundleReleaseAar
               //artifact sourcesJar
               //artifact packageJavadoc
            }
         }
       }
    }
    

    Reference https://github.com/moberwasserlechner/capacitor-oauth2/issues/10

    0 讨论(0)
  • 2021-01-11 23:30

    Short Answer :

    You need to enclose the publishing {} block inside a project.afterEvaluate as follows:

    project.afterEvaluate {
        publishing {
            publications {
                aar(MavenPublication) {
                    groupId libraryGroupId
                    version libraryVersion
                    artifactId libraryArtifactId
    
                    artifact bundleReleaseAar
                    //artifact sourcesJar
                    //artifact packageJavadoc
                }
            }
        }
    }
    

    Long Answer :

    Prior to gradle version 4.8, publishing block was implicitly treated as if all the logic inside it was executed after the project was evaluated. This was only block that behaved this way and this behavior was discontinued post gradle version 4.8 for consistency's sake. bundleReleaseAar task seems to be available only after project evaluation is complete and therefore to maintain behavior it must be explicitly enclosed inside project.afterEvaluate{}

    Reference : https://docs.gradle.org/current/userguide/upgrading_version_4.html#rel4.8:deferred_configuration

    0 讨论(0)
  • 2021-01-11 23:47

    I fix this problem change artifact from:

    artifact bundleReleaseAar
    

    to:

    artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
    

    this help me Gradle sync success, but i must call assembleRelease directly, before ./gradlew publish

    0 讨论(0)
提交回复
热议问题