Search code examples
gradlepublish

Need to capture activity of the UploadArchive and publish Gradle tasks


I have a scenario where I need to capture below details in the init.gradle file.

Can we get all the activity of task ?

the Inputs params for UploadArchive and publish task, which repo is the artifact getting uploaded, all the GAV details …as POM can be customize within uploadArchive task.

We have applications running v3.5 to v6.3 versions of Gradle.

Can you please assist

Hi @PrasadU

Can we determine which deployment url, uploadArchive task will pick at runtime.

uploadArchive {
    repositories {
       mavenDeployer {
            repository(url: ReleaseURL) {
                authentication(userName: Username, password: Password)
            }
            snapshotRepository(url: SnapshotURL ) {
                authentication(userName: Username, password: Password)
            }
        }
    }
}

Solution

  • A task to list the same be made as below

    publishing {
        publications {
            maven(MavenPublication) {
                groupId = 'abc.xyz'
                artifactId = 'overr-name'
                version = '1.1-OV'
    
                from components.java
            }
        }
        repositories {
            maven {
                url = uri("$buildDir/repos/releases")
            }
            maven {
                url = uri("$buildDir/repos/snaps")
            }
        }
    }
    
    task printML() {
        doLast {
            tasks.findAll {task ->
                if (task.name.matches("publish.*PublicationToMavenLocal")) {
                    def publication = task.publicationInternal
                    println("Local => $publication.artifactId $publication.groupId $publication.version")
                }
                if (task.name.matches("publish.*PublicationTo.*Repository")) {
                    def publication = task.publicationInternal
                    println("Remote => $publication.artifactId $publication.groupId $publication.version  $task.repository.url")
                }
            }
        }
    }
    

    Sample output

    > Task :printML
    Remote => overr-name abc.xyz 1.1-OV  file:/Users/projects/Store/combined-samples/build/repos/snaps
    Local => overr-name abc.xyz 1.1-OV
    Remote => overr-name abc.xyz 1.1-OV  file:/Users/projects/Store/combined-samples/build/repos/releases