This message was deleted.
# community-support
s
This message was deleted.
a
you could add an additional action for all publishing tasks that would log the GAV to console
Copy code
tasks.withType<AbstractPublishToMaven>().configureEach {
    val publicationGAV = provider { publication?.run { "$group:$artifactId:$version" } }
    doLast("log publication GAV") {
        if (publicationGAV.isPresent) {
            logger.lifecycle("[task: ${path}] ${publicationGAV.get()}")
        }
    }
}
That could be amended to write the GAV to a file too.
alternatively you could try grabbing the generated metadata file. If you run
./gradlew publishToMavenLocal
then take a look in the build dir for something like
build/publications/XYZ/module.json
. Because it’s JSON it’ll be a bit easier to parse than a pom.xml. That file will be generated by a task named something like ‘generateMetadataFileForXYZPublication’. So you could add a
doLast {}
action, or a separate finalizer task, for all ‘generateMetadataFileForXYZPublication’ tasks that would read the file and log it to console or copy it to a directory for your script to work on...
e
actually why not just look at the publications extension directly?
Copy code
tasks.register("listPublications") {
    doLast {
        for (publication in publishing.publications.filterIsInstance<MavenPublication>()) {
            println("${publication.groupId}:${publication.artifactId}:${publication.version}")
        }
    }
}
d
Ah,
publications
, I was trying
configurations
and looking to access the
runtimeElements
and
archives
, and not able to get all the right information. Though using
doLast
might also have helped. But the publishToMavenLocal works just as nicely and won't require gradle files to be modified (will be turning this into a github action to help call promote on the artifact hosting tool and allow us to switch the tool used without needing to rework everyones gradle file. Which is perfect. Many thanks for the pointers. I presume
filterIsInstance
is kotlin? I had to switch the code to the following as I'm using groovy but I presume this is the expected way to achieve the same (my groovy is rusty):
Copy code
tasks.register("listPublications") {
    doLast {
        for (publication in publishing.publications.findAll{it instanceof MavenPublication}) {
            println("${publication.groupId}:${publication.artifactId}:${publication.version}")
        }
    }
}
If I need to switch to handle multiple publications from one project I may switch from getting the json file to printing them out using the above task and run
./gradlew listPublications --console plain --quiet
instead
a
sounds like a good plan!
will be turning this into a github action to help call promote on the artifact hosting tool and allow us to switch the tool used without needing to rework everyones gradle file
Just curious: did you consider turning it into a Gradle plugin instead? Then you wouldn’t need to pipe/grep stdout, and you could write it in Kotlin (or Java or Groovy, whatever works best)
d
We'll have npm, python, generic, and maven artifacts, so having an action to handle this cleanly for projects without needing to expose the backing service too much is probably better for this particular situation. If it was just one or two types then a native plugin/library probably would make sense
a
ah yeah, makes sense