需要捕获UploadArchive的活动并发布Gradle任务 [英] Need to capture activity of the UploadArchive and publish Gradle tasks

查看:106
本文介绍了需要捕获UploadArchive的活动并发布Gradle任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一种情况下,我需要在init.gradle文件中捕获以下详细信息.

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

我们可以得到任务的所有活动吗?

Can we get all the activity of task ?

UploadArchive和publish任务的Inputs参数,该回购是要上传的工件,所有GAV详细信息……因为可以在uploadArchive任务中自定义POM.

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.

我们有运行v3.5到v6.3版本的Gradle的应用程序.

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

嗨@PrasadU

我们能否确定运行时将选择哪个部署URL,uploadArchive任务.

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

推荐答案

列出以下内容的任务

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

样本输出

> 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

这篇关于需要捕获UploadArchive的活动并发布Gradle任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆