我们有一个常春藤存储库,我们正在使用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应用程序来推广工件。
答案 0 :(得分:1)
我不清楚为什么使用工具API实现促销,而不是作为常规的Gradle任务或插件。无论如何,IvyPublication
既未使用IvyPublication#from
配置,也未使用IvyPublication#artifact
配置。因此他们不会有任何文物。