Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 5.x - Error publishing my library to Maven Local

I have just upgraded my Gradle to 5.x and I'm having a new error when I try to sync my library project. This error is coming from a publishing block that I need to publish my library to maven local.

This is what I used to do with Gradle 4 and it worked just fine :

apply plugin: 'maven-publish'
publishing {
    publications {
        library(MavenPublication) {
            groupId = 'myGroupId'
            artifactId = 'myArtifactId'
            version = android.defaultConfig.versionName

            artifact bundleDebugAar
        }
    }
}

With Gradle 5, I now have an error about the artifact when I sync the gradle project:

ERROR: Could not get unknown property 'bundleDebugAar' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.

When I remove the artifact line, I can sync the project but when I'm trying to publishToMavenLocal my build is failing :

Execution failed for task ':mypackage:generatePomFileForLibraryPublication'.

No value has been specified for this provider.

I looked in the gradle upgrading guide but I don't know how to solve my issue: https://docs.gradle.org/5.0/userguide/upgrading_version_4.html#rel5.0:pom_compile_runtime_separation

Can anybody tell me what's changed in this new version that I'm not seeing please ? Thanks.

like image 892
William Mouliné Avatar asked Apr 18 '19 13:04

William Mouliné


People also ask

Does Gradle use Maven local repository?

Bookmark this question. Show activity on this post.

Can you use Gradle and Maven together?

Short answer: yes. There's no conflict between having two independent build scripts for the same project, one in Maven and one in Gradle.

What is groupId and artifactId in Gradle?

In Gradle, the groupId is known just as group , the artifactId is known as name , and the version is identically version .


3 Answers

you may try this.

project.afterEvaluate {
    publishing {
        publications {
            library(MavenPublication) {
            groupId = 'myGroupId'
            artifactId = 'myArtifactId'
            version = android.defaultConfig.versionName

            artifact bundleDebugAar
        }
        }
    }
}
like image 129
Reddy Avatar answered Nov 08 '22 00:11

Reddy


With gradle 4.8+ you have to enclose the publishing{} block inside a project.afterEvaluate

project.afterEvaluate {
    publishing {
        publications {
            aar(MavenPublication) {
                //...
                artifact bundleReleaseAar
            }
        }
    }
}

You can find the 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.

like image 24
Gabriele Mariotti Avatar answered Nov 07 '22 22:11

Gabriele Mariotti


Put this inside project.afterEvaluate:

project.afterEvaluate {
    publishing {
        publications {
            mavenDebugAAR(MavenPublication) {
                artifact bundleDebugAar
            }
        }
    }
}
like image 25
zhou chen Avatar answered Nov 07 '22 23:11

zhou chen