Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not get unknown property 'release' for SoftwareComponentInternal - Maven publish plugin project gradle

I have an Android project with multiple modules and I want to publish them to self-hosted maven repo. I earlier had the publishing code present in individual modules and things worked just fine. I am now trying to move the publishing code into the project build.gradle so that I can reuse the code. The code inside my individual modules was:

afterEvaluate {
        // To avoid publishing the applications inside the project...
        if (!plugins.hasPlugin("android")) {
            publishing {
                publications {
                    mavenAar(MavenPublication) {
                        artifactId "$project.name"
                        from components.release
                    }
                }
                repositories {
                    .... My repo details and credentials .......
                }
            }
        }
    }

and things worked just fine. When I moved the code to the project build.gradle, like this:

subprojects {
    apply plugin: 'maven-publish'

    afterEvaluate {
        // To avoid publishing of the applications inside the project ..
        if (!plugins.hasPlugin("android")) {
            publishing {
                publications {
                    mavenAar(MavenPublication) {
                        artifactId "$project.name"
                        from components.release
                    }
                }
                repositories {
                    .... My reop details and creddentials  .....
                }
            }
        }
    }
}

I started getting the following error when running the publish task:

A problem occurred configuring project ':mymodule'.
> Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

Can someone point out the problem here?

like image 486
Swapnil Avatar asked Apr 25 '21 12:04

Swapnil


People also ask

What is Maven publication in Gradle?

MavenPublication A MavenPublication is the representation/configuration of how Gradle should publish something in Maven format. You directly add a named Maven Publication the project's publishing.publications container by providing MavenPublication as the type.

Is it possible to provide multiple components in a mavenpublication?

For any individual MavenPublication, only a single component can be provided in this way. The following example demonstrates how to publish the 'java' component to a Maven repository.

What went wrong with test-Java-multiproject-API?

* What went wrong: A problem occurred configuring project ':test-java-multiproject-api'. > Could not get unknown property 'components' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication. As far as I know, both situations should be roughly the same.

How is each source interpreted in Maven publication?

Each supplied source is interpreted as per MavenPublication.artifact (java.lang.Object) . For example, to exclude the dependencies declared by a component and instead use a custom set of artifacts: Silences all the compatibility warnings for the Maven publication.


1 Answers

I came across this after updating AGP for Jitpack. Both the MavenPublication block and the components.release line appear to use your build variant name. So if you have a standard debug and release variant it would look like this:

afterEvaluate {
publishing {
    publications {
        release(MavenPublication) {
            from components.release
            groupId = 'com.my.group'
            artifactId = 'id'
            version = Config.libraryVersion
        }
    }
}

But if you have a build variant with a name other than release, you need to use that:

afterEvaluate {
    publishing {
        publications {
            productionRelease(MavenPublication) {
                from components.productionRelease
                groupId = 'com.my.group'
                artifactId = 'id'
                version = Config.libraryVersion
            }
        }
    }
like image 51
Daniel Wilson Avatar answered Sep 17 '22 08:09

Daniel Wilson