groovy - 重新发布 gradle 工件

标签 groovy gradle ivy

我们有一个 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 应用程序来推广工件。

最佳答案

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

关于groovy - 重新发布 gradle 工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22101653/

相关文章:

java - Java导入Minecraft Mod的build.gradle文件

authentication - 在抢占模式下使用groovy http-builder

groovy - 为什么Groovy的map没有metaClass?

eclipse - 在多项目Buildship工作区中添加项目依赖项

Android Ivy ActionBarSherlock

java - Ivy 使用 Maven 快照 "revision already resolved"

sbt - 用 SBT 0.13 中的 project.properties 替换 externalIvyFile 中的属性占位符?

docker - 在groovy代码下实现时,文件描述符错误

java - groovy 如何使用名称创建数组?

gradle - 评估旧版Gradle项目 `org/gradle/listener/ActionBroadcast`的问题