【问题标题】:How to publish(deploy) multiple zip files to artifactory using gradle?如何使用 gradle 发布(部署)多个 zip 文件到工件?
【发布时间】:2015-11-03 07:44:17
【问题描述】:

我想使用 gradle 脚本将多个 zip 文件(来自不同目录)上传到工件。我可以使用以下代码上传单个发行版。

    distributions {
        main {
            baseName = 'sample'
            contents {
                  from{'src/main/dist/sample'} 
            }
        }

    }
    publishing {
        repositories {
            maven {
                url "${artifactoryURL}/myFiles"
                credentials {
                    username artifactoryUser
                    password artifactoryPassword
                }
            }
        }
        publications {
            distribution(MavenPublication) {
                groupId 'com.test'
                artifactId 'sample'
                version version
                artifact (distZip) {
                }
            }
    }
    }

请帮助上传来自不同来源(“src/main/dist/second”)的多个 zip 文件。

【问题讨论】:

    标签: gradle build.gradle


    【解决方案1】:

    这是 build.gragle 的完整示例。要发布 zip,您应该运行 distZip artifactoryPublish

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
        }
    }
    
    apply plugin: 'com.jfrog.artifactory'
    apply plugin: 'maven-publish'
    apply plugin: 'distribution'
    
    //Defining list of our distributions, every value is map which contains value and version of every distribution
    def dists = [
        [name:'sample', version: 1], 
        [name:'second', version: 1]
    ]
    
    distributions {
        //Creating distribution from each value of the distributions list defined above
        dists.each { dist ->
            "$dist.name" {
                baseName = "$dist.name"
                contents {
                    from{"src/main/dist/${dist.name}"} 
                }
            }
        }
    }
    
    //Every new distribution creates task "${distributionName}DistZip" so we make posible to run them with base task distZip
    distZip.dependsOn {
        tasks.findAll{ task -> task.name.endsWith('DistZip') }
    }
    
    publishing {
        publications {
            //Again iterating list to make publication for every distribution
            dists.each { dist ->
                //Every publication has name of the distibution
                "$dist.name"(MavenPublication) {
                    groupId "test"
                    version = dist.version
                    artifactId = dist.name
    
                    artifact("$buildDir/distributions/${dist.name}.zip")
                }
            }
        }
    }
    
    artifactory {
        contextUrl = "$URL"
        publish {
            repository {
                repoKey = 'REPO_KEY'
    
                username = USER_NAME
                password = PASSWORD
            }
            defaults {
                //Publish every distribution to Artifactory
                dists.each { dist ->
                    publications(dist.name)
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      相关资源
      最近更新 更多