Gradle上传多个仓库

2019-07-19  本文已影响0人  sollian

有时候我们需要将library上传到多个Maven仓库,这种情况下uploadArchives任务就不能满足需求了。可以通过如下自定义Upload任务的方式解决:

ext{
    GROUP = ''
    VERSION_NAME = '0'
}

task uploadMaven1(type: Upload) {
    configuration = configurations.archives
    repositories {
        mavenDeployer {
            repository(url: '') {
                authentication(userName: "", password: "")
            }
            snapshotRepository(url: '') {
                authentication(userName: "", password: "")
            }
            pom.groupId = GROUP
            pom.artifactId = project.name
            pom.version = VERSION_NAME
            pom.whenConfigured { pom ->
                pom.dependencies.each { dep ->
                    if (dep.getVersion() == "unspecified") {
                        dep.setGroupId(GROUP)
                        dep.setVersion(VERSION_NAME)
                    }
                }
            }
            println("${project} : ${pom.version} package success")
        }
    }
}
task uploadMaven2(type: Upload) {
    configuration = configurations.archives
    repositories {
        mavenDeployer {
            repository(url: '') {
                authentication(userName: "", password: "")
            }
            snapshotRepository(url: '') {
                authentication(userName: "", password: "")
            }
            pom.groupId = GROUP
            pom.artifactId = project.name
            pom.version = VERSION_NAME
            pom.whenConfigured { pom ->
                pom.dependencies.each { dep ->
                    if (dep.getVersion() == "unspecified") {
                        dep.setGroupId(GROUP)
                        dep.setVersion(VERSION_NAME)
                    }
                }
            }
            println("${project} : ${pom.version} package success")
        }
    }
}

task uploadMaven {
    dependsOn(uploadMaven1, uploadMaven2)
}
上一篇下一篇

猜你喜欢

热点阅读