Gradle 发布到 Artifactory 的特定 repo
Posted
技术标签:
【中文标题】Gradle 发布到 Artifactory 的特定 repo【英文标题】:Gradle publish to the specific repo of the Artifactory 【发布时间】:2015-12-12 01:17:24 【问题描述】:我正在尝试使用 gradle 设置工件(APK/aar 文件)构建过程,类似于我习惯使用 maven 的方式。
mvn release:prepare (Adjusts version, checks into SVN, creates the tag)
mvn release:perform -Dgoals=deploy (Pushes the artifact to http://artifactory.XXX.local/artifactory/libs-releases-local/)
我希望能够运行 gradle 命令并获得类似的结果。我正在使用https://github.com/researchgate/gradle-release 插件进行发布管理(效果很好,所以我很擅长发布)。但是当我运行命令 gradlew artifactoryPublish
时,工件被部署在其他位置(好像它不尊重 gradle 文件中的 repoKey)
D:\my-lib-android-0.0.2>gradlew artifactoryPublish ... ... [buildinfo] 不为此构建使用 buildInfo 属性文件。 :artifactoryPublish 将构建描述符部署到: http://artifactory.XXX.local/artifactory/api/build 构建成功 部署。在 Artifactory 中浏览它 http://artifactory.XXX.local/artifactory/webapp/builds/my-lib-android-0.0.2/1449880830949>
构建成功
总时间:9.692 秒
所以我的问题是如何修复我的设置,以便将工件推送到类似于此的 URL:
http://artifactory.XXX.local/artifactory/libs-releases-local/com/example/my-lib-android/0.0.2/my-lib-android-0.0.2.aar
build.gradle 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
repositories
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:1.3.0'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.2')
classpath 'net.researchgate:gradle-release:2.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
plugins
id 'net.researchgate.release' version '2.3.4'
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply plugin: 'net.researchgate.release'
allprojects
repositories
jcenter()
maven
url 'http://artifactory.XXX.local/artifactory/libs-releases-local'
artifactory
contextUrl = "$artifactory_contextUrl"
//The base Artifactory URL if not overridden by the publisher/resolver
publish
repository
repoKey = "libs-releases-local"
username = "$artifactory_user"
password = "$artifactory_password"
maven = true
release
revertOnFail = false
task build
gradle.properties 文件:
version=my-lib-android-0.0.3-SNAPSHOT
artifactory_user=myUserName
artifactory_password=myPasssword
artifactory_contextUrl=http://artifactory.XXX.local/artifactory
【问题讨论】:
基于用户@RaGe 的评论(现已删除),我添加了插件id "com.jfrog.artifactory" version "3.1.0"
以及artifactoryPublish .. ..
块。但这没有帮助。
你使用的是maven-publish
,你应该使用artifactory-publish
而不是artifactory
,这里的答案是:***.com/questions/22352475/…
您是否为您的 maven-publish 插件定义了任何 publishing
?
谢谢!我明天试试。
多读一些,maven-publish
适用于传统的 java 项目,对于 android 项目,您可能想要使用 android-maven
【参考方案1】:
使用android-maven
插件:
buildscript
repositories
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'com.github.dcendents:android-maven-plugin:1.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.2.0'
apply plugin: 'android-library'
apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'android-maven'
configurations
published
task sourceJar(type: Jar)
from android.sourceSets.main.java
classifier "sources"
artifactoryPublish
dependsOn sourceJar
artifacts
published sourceJar
artifactory
contextUrl = "$artifactory_contextUrl"
publish
repository
repoKey = "libs-releases-local"
username = "$artifactory_user"
password = "$artifactory_password"
defaults
publishConfigs('archives', 'published')
publishPom = true //Publish generated POM files to Artifactory (true by default)
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
【讨论】:
现在当我执行gradlew clean
我得到.. "buildToolsVersion is not specified."【参考方案2】:
我通常用这样的 mavenDeployer-plugin 来做。 不知道它是否符合你的情况,但我将把它留在这里。
apply plugin: 'maven'
uploadArchives
repositories
mavenDeployer
repository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/releases')
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
snapshotRepository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/snapshots')
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
pom.groupId = "groupId"
pom.artifactId = "artifactId"
pom.version = "$versionMajor.$versionMinor.$versionPatch"
一些进一步阅读本地回购here
【讨论】:
我还没有尝试这个!以上是关于Gradle 发布到 Artifactory 的特定 repo的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Gradle 1.12 版发布(部署)本地(.war .jar)文件到 Artifactory?
不允许用户使用 Gradle 将“.json”部署到 Artifactory
使用 Gradle 将工件上传到 JFrog Artifactory