Slackbot
06/28/2023, 9:25 PMAdam
06/28/2023, 9:38 PMtasks.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.Adam
06/28/2023, 9:47 PM./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...ephemient
06/28/2023, 9:49 PMtasks.register("listPublications") {
doLast {
for (publication in publishing.publications.filterIsInstance<MavenPublication>()) {
println("${publication.groupId}:${publication.artifactId}:${publication.version}")
}
}
}Darragh Bailey
06/29/2023, 7:04 AMpublications , 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):
tasks.register("listPublications") {
doLast {
for (publication in publishing.publications.findAll{it instanceof MavenPublication}) {
println("${publication.groupId}:${publication.artifactId}:${publication.version}")
}
}
}Darragh Bailey
06/29/2023, 7:10 AM./gradlew listPublications --console plain --quiet insteadAdam
06/29/2023, 7:23 AMwill 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 fileJust 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)
Darragh Bailey
06/29/2023, 7:32 AMAdam
06/29/2023, 7:33 AM