如何使用Gradle将RPM文件上传到Artifactory? Gradle总是使用不适合YUM存储库的maven样式直接布局来上传文件。从Gradle上传RPM到Artifactory
3
A
回答
3
这里的问题是,Gradle坚持要以maven样式的目录格式group-id/version/artifact
上传所有内容,而yum存储库需要平面布局。这里有两种方法 - 使用Artifactory插件或Gradle更新的发布机制。我只能得到这个与后者合作。
我在这里假设您使用的是Gradle ospackage plugin,并且已经创建了RPM版本。在我的情况下,RPM任务的名称是distRpm
。例如:
task distRpm(type: Rpm) {
packageName = 'my_package'
version = version
release = gitHash
arch = 'X86_64'
os = 'LINUX'
// Etc
}
添加常春藤发布插件到您的项目:
apply plugin: 'ivy-publish'
,然后添加一个出版块:
publishing {
publications {
rpm(IvyPublication) {
artifact distRpm.outputs.getFiles().getSingleFile()
/* Ivy plugin forces an organisation to be set. Set it to anything
as the pattern layout later supresses it from appearing in the filename */
organisation 'dummy'
}
}
repositories {
ivy {
credentials {
username 'yourArtifactoryUsername'
password 'yourArtifactoryPassword'
}
url 'https://your-artifactory-server/artifactory/default.yum.local/'
layout "pattern", {
artifact "${distRpm.outputs.getFiles().getSingleFile().getName()}"
}
}
}
}
常春藤出版允许你指定的目录和上传的文件名模式。这被覆盖为简单的RPM的确切文件名。
0
这是我的代码片段与摇篮Artifactory的插件
应用插件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.0"
}
}
apply plugin: 'ivy-publish'
apply plugin: 'com.jfrog.artifactory'
配置artifactory的
artifactoryPublish {}.dependsOn(buildRpm)
publishing.publications.create('yum-publication', IvyPublication) {
artifact buildRpm.outputs.getFiles().getSingleFile()
}
artifactory {
contextUrl = 'https://artifactory.acme.com/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver
publish {
//A closure defining publishing information
repository {
repoKey = 'demo-yum' //The Artifactory repository key to publish to
username ="${artifactory_user}"
password = "${artifactory_password}"
ivy {
artifactLayout = "${buildRpm.outputs.getFiles().getSingleFile().getName()}"
}
}
defaults {
//List of Gradle Publications (names or objects) from which to collect the list of artifacts to be deployed to Artifactory.
publications ('yum-publication')
publishBuildInfo = false //Publish build-info to Artifactory (true by default)
publishArtifacts = true //Publish artifacts to Artifactory (true by default)
publishPom = false //Publish generated POM files to Artifactory (true by default).
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default).
}
}
}
我得到了 “摇篮发布attemps上传RPM来artifactory的YUM回购两次” http://stackoverflow.com/questions/40001668/gradle-publish-attemps-to-upload-rpm-to-artifactory-yum-repo-twice-second-time#comment69674847_40001668用这种方法 – popalka
这是一个**错误的解决方案**,很简单,因为它在使用多个发布时会中断,或者像@popalka一样,上传多个工件时会中断。您应该使用真实模式,而不是硬编码您期望的单个文件的名称。 –
由于Ivy占位符'[originalname]'尚未在Gradle中实现,所以应该使用另一个占位符(例如'[module]')并将文件名放入该属性中。看看[这个最简单的例子](https://stackoverflow.com/a/48829037/3950370)。 –