Need to capture activity of the UploadArchive and publish Gradle tasks

≡放荡痞女 提交于 2020-08-17 10:35:32

问题


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)
            }
        }
    }
}

回答1:


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


来源:https://stackoverflow.com/questions/62838908/need-to-capture-activity-of-the-uploadarchive-and-publish-gradle-tasks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!