如何使用Gradle将RPM文件上传到Artifactory? Gradle总是使用maven样式的直接布局上传文件,这不适合YUM存储库。
答案 0 :(得分:4)
这里的问题是Gradle坚持以group-id/version/artifact
的maven样式目录格式上传所有内容,而yum存储库需要平面布局。这里有两种方法 - 使用Artifactory插件或Gradles更新的发布机制。我只能让它与后者合作。
我在这里假设您正在使用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的确切文件名。
答案 1 :(得分:1)
这是我使用Gradle 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'
配置神器
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).
}
}
}