【问题标题】:Re-publish gradle artifacts重新发布 gradle 工件
【发布时间】:2014-04-01 20:07:18
【问题描述】:

我们有一个 ivy 存储库,我们正在使用 gradle 进行依赖管理和构建框架。当一个工件被确定为生产就绪时,我们不想再次构建它,所以我们只想通过一个利用 Gradle 和工具 API 来完成大部分工作的 Web 应用程序来“提升”现有的工件为我们举起重担。

目前,我正在将工件复制到本地文件夹并运行另一个 build.gradle,它只是重新发布它。我们将其发布到现有存储库中的一个新文件夹,以及发布存储库中的一个文件夹。

这样做,它只是将 ivy.xml 发布到两个位置。

我猜这是因为工件所在的位置。

PromotionService.groovy

void promote(Project project, Build build, String newVersion) {
    def artifactLocation = "/path/to/repository"
    // we are generating this build.gradle and copying it
    def buildFileText = new File('promote.gradle').getText('UTF-8')
    def artifacts = buildDao.findArtifactsByBuild(build)
    def localBuildFolderPath = "/path/to/local/gradle/build"
    def localBuildFolder = new File(localBuildFolderPath)
    localBuildFolder.mkdirs()
    // remove everything currently in the directory
    def buildFiles = localBuildFolder.listFiles()
    buildFiles.each {
        it.delete()
    }
    def newFile = new File("/path/to/local/gradle/build.gradle")
    newFile.mkdirs()
    if (newFile.exists())
        newFile.delete()
    newFile << buildFileText
    artifacts.each { VersionedArtifact it ->
        def folder = new File("${artifactLocation}/${it.module}/${build.branch}/${it.version}")
        def files = folder.listFiles()
        files.each { File from ->
            // remove version number from file name
            String fromName = from.name
            def matcher = fromName =~ /(.*?)-(\d)+\.(\d)+\.(\d)+(\.\d+)?\.(.*)/
            fromName = "${matcher[0][1]}.${matcher[0][6]}"
            File to = new File("${localBuildFolderPath}/${it.module}/${fromName}")
            to.mkdirs()
            if (to.exists()) to.delete()
            // wrapper for Guava's Files.copy()
            FileUtil.copy(from, to)
        }

        ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File("${workingDir}/gradle")).connect()
        connection.newBuild()
            .forTasks("publishReleaseBranchPublicationToIvyRepository", "publishReleaseRepoPublicationToReleaseRepository")
            .withArguments("-PMODULE=${it.module}", "-PVERSION=${it.version}", "-PNEWVERSION=${newVersion}")
            .run()
    }
}

build.gradle

apply plugin: 'groovy'
apply plugin: 'ivy-publish'

publishing {
  publications {
    releaseBranch(IvyPublication) {
        organisation 'our-organization'
        module MODULE
        revision VERSION
        descriptor.status = 'release'

        configurations { archive {
            } }
    }
    releaseRepo(IvyPublication) {
        organisation 'our-organization'
        module MODULE
        revision NEWVERSION
        descriptor.status = 'release'

        configurations { archive {
        }}
    }
}
repositories {
    ivy {
        name 'ivy'
        url "/path/to/ivy/repo"
        layout "pattern", {
            ivy "[organisation]/[module]/release/[revision]/[module]-[revision].xml"
            artifact "[organisation]/[module]/release/[revision]/[artifact](-[classifier])-[revision].[ext]"
        }
    }
    ivy {
        name 'release'
        url "/path/to/release/repo"
        layout "pattern", {
            ivy "[organisation]/[module]/[revision]/[module]-[revision].xml"
            artifact "[organization]/[module]/[revision]/[artifact](-[classifier])-[revision].[ext]"
        }
    }
  }
}

编辑:更清楚地表明我们正在编写一个 Web 应用程序来推广工件。

【问题讨论】:

    标签: groovy gradle ivy


    【解决方案1】:

    我不清楚为什么促销是使用工具 API 实现的,而不是作为常规的 Gradle 任务或插件。无论如何,IvyPublications 既没有使用IvyPublication#from 配置,也没有使用IvyPublication#artifact。因此他们不会有任何文物。

    【讨论】:

    • 谢谢,彼得。自从我写了这个问题(刚刚从 components.java 添加)以来,我已经对此进行了一些迭代,并且它正在发布工件(我稍后将对其进行编辑)。我只想写一个任务,但我不知道如何让它重新发布工件,修改 ivy 状态以发布,并维护所有依赖项。
    • 现在值得一提,因为我意识到提到我们正在构建一个利用工具 API 来运行 Gradle 任务的 Web 应用程序是非常重要的。此应用程序处理促销活动,但我们想利用 Gradle 为我们完成大部分繁重的工作。
    猜你喜欢
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2013-09-21
    • 2020-08-09
    • 1970-01-01
    • 2016-09-23
    • 2021-03-08
    相关资源
    最近更新 更多