Retrieve GAV of application automatically

Hi,

I want to retrieve GAV(groupId, artifactId, version) of component which is going to be uploaded on Nexus 3.
I am using maven-publish plugin for this task.
Any idea on how I can retrieve GAV of single as well as multi-project builds in Jenkins so that I can use them for Component Tagging.

The default GAV of a publication are the group, name, and version attributes of the Gradle project. I’m not very sure what do you mean by “retrieving” them when you are the one who is specifying them to begin with.

I am from DevOps and here we getting various types of applications to build. So the actual developer is mentioning these GAV in build.gradle file.
In some multi-project gradle build artifactId and version are generated dynamically we have that logic as well.
I just want to get them out during build or publish task

When you use the maven-publish plugin, you can find all poms under the respective projects build directory - is that good enough?

Keep in mind that if the build was not clean, you may find there stale poms, and if the build didn’t publish anything - no poms.

Yes I am aware of this pom file creation step.
But here as well we have problem like how we can determine exact location of poms in case of multi-project build. Is there any way to do this?

I am not sure what problem you are trying to solve exactly. It looks to me like you have all the knowledge you need - you know poms get generated as files, you know where they are, you know that the id’s are in the POMs. What is missing?

Fer example, what’s wrong with the obvious find . -name 'pom-*.xml' -path '*/build/publications/*' ?

You can write a task that accesses the publications and their GAV via the publication container. For example:

apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'org.some'
version = '1.0.0'

publishing {
    publications {
        somePub( MavenPublication ) {
            from components.java
        }
        someOtherPub( MavenPublication ) {
            groupId = 'org.other'
            artifactId = 'cool-thing'
            version = '1.2.3'
        }
    }
}

task dumpPublications {
    doLast {
        publishing.publications.withType( MavenPublication ) { pub ->
            logger.lifecycle "${pub.name} => ${pub.groupId}:${pub.artifactId}:${pub.version}"
        }
    }
}

Output:

$ gradle dumpPublications
> Task :dumpPublications
someOtherPub => org.other:cool-thing:1.2.3
somePub => org.some:gav-test:1.0.0
1 Like