[关闭]
@xtccc 2016-09-24T01:43:49.000000Z 字数 1946 阅读 2448

发布artifact到repo

给我写信
GitHub

此处输入图片的描述

Gradle



1. 发布到自己的repo中


如果要将某个artifact发布到自己管理的某个仓库中,在该artifact所在项目的build.gradle:

  1. uploadArchives {
  2. repositories {
  3. mavenDeployer {
  4. repository(url: "http://aa.bb.cc.dd:8081/path/to/repo") {
  5. authentication(userName: "xx", password: "yy")
  6. }
  7. pom.version = "3.2.0"
  8. pom.artifactId = "s3-plugin"
  9. pom.groupId = "com.gridx"
  10. }
  11. }
  12. }




2. 发布到jcenter


放在自己的仓库里,其他开发者是看不到的,所以我们可以把自己的artifact托管在jcenter中。

2.1 准备工作

首先要到JFrog Bintray去注册一个账号,然后创建一个名为maven的repository。

接着,到自己账户的管理页面中,获取自己的API Key:

image_1atcs0kub1jba16sm5nn14ng1ibg19.png-58.5kB


2.2 编写自己的artifact

在自己项目的根目录下,建立一个名为local.properties的文件,内容为:

  1. bintray.user=xtccc
  2. bintray.apikey=<API Key>

这个文件要自己做好保密。

在要发布的项目的build.gradle中,添加一些必须的内容。
下面是一个完整的例子,相信你一看就明白:

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
  7. // NOTE: Do not place your application dependencies here; they belong
  8. // in the individual module build.gradle files
  9. }
  10. }
  11. group 'cn.gridx'
  12. version '1.0-RELEASE'
  13. apply plugin: 'java'
  14. apply plugin: 'scala'
  15. apply plugin: 'maven'
  16. apply plugin: 'com.jfrog.bintray'
  17. repositories {
  18. mavenCentral()
  19. }
  20. dependencies {
  21. compile gradleApi()
  22. compile 'com.amazonaws:aws-java-sdk:1.9.6',
  23. 'org.scala-lang:scala-library:2.10.4'
  24. }
  25. // 发布时必须有doc/sources才能通过审核
  26. task jarSources(type:Jar){
  27. from sourceSets.main.allSource
  28. classifier = 'source'
  29. }
  30. task scaladocJar(type: Jar, dependsOn: scaladoc) {
  31. classifier = 'scaladoc'
  32. from scaladoc.destinationDir
  33. }
  34. install {
  35. repositories.mavenInstaller {
  36. pom {
  37. project {
  38. packaging 'jar'
  39. }
  40. }
  41. }
  42. }
  43. artifacts {
  44. archives scaladocJar
  45. archives jarSources
  46. }
  47. def gitUrl = 'https://github.com/TaoXiao/s3syncer.git'
  48. Properties properties = new Properties()
  49. properties.load(project.rootProject.file('local.properties').newDataInputStream())
  50. bintray {
  51. user = properties.getProperty("bintray.user")
  52. key = properties.getProperty("bintray.apikey")
  53. configurations = ['archives']
  54. pkg {
  55. repo = "maven"
  56. name = "s3-syncer-plugin-for-gradle"
  57. vcsUrl = gitUrl
  58. licenses = ["Apache-2.0"]
  59. publish = true
  60. }
  61. }



执行命令即可:

  1. gradle install bintrayUpload


成功之后,你应该能在页面上看到一个名为s3-syncer-plugin-for-gradle的package:

image_1atcsuf411p78kaaq65frghb01m.png-42.5kB


2.3 发布到MavenCentral

进入s3-syncer-plugin-for-gradle package,点击Add to JCenter

image_1atct7hdu1tqfhro1icp1juk1gns23.png-122.3kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注