publish-mavencentral.gradle 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. apply plugin: 'maven-publish'
  2. apply plugin: 'signing'
  3. task androidSourcesJar(type: Jar) {
  4. classifier = 'sources'
  5. from android.sourceSets.main.java.source
  6. }
  7. ext["signing.keyId"] = ''
  8. ext["signing.password"] = ''
  9. ext["signing.secretKeyRingFile"] = ''
  10. ext["ossrhUsername"] = ''
  11. ext["ossrhPassword"] = ''
  12. File secretPropsFile = project.rootProject.file('local.properties')
  13. if (secretPropsFile.exists()) {
  14. println "Found secret props file, loading props"
  15. Properties p = new Properties()
  16. p.load(new FileInputStream(secretPropsFile))
  17. p.each { name, value ->
  18. ext[name] = value
  19. }
  20. } else {
  21. println "No props file, loading env vars"
  22. }
  23. publishing {
  24. publications {
  25. release(MavenPublication) {
  26. // The coordinates of the library, being set from variables that
  27. // we'll set up in a moment
  28. groupId PUBLISH_GROUP_ID
  29. artifactId PUBLISH_ARTIFACT_ID
  30. version PUBLISH_VERSION
  31. // Two artifacts, the `aar` and the sources
  32. artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
  33. artifact androidSourcesJar
  34. // Self-explanatory metadata for the most part
  35. pom {
  36. name = PUBLISH_ARTIFACT_ID
  37. description = 'Kongzue DialogX'
  38. // If your project has a dedicated site, use its URL here
  39. url = 'https://github.com/kongzue/DialogX/'
  40. licenses {
  41. license {
  42. //协议类型,一般默认Apache License2.0的话不用改:
  43. name = 'The Apache License, Version 2.0'
  44. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  45. }
  46. }
  47. developers {
  48. developer {
  49. id = 'kongzue'
  50. name = 'kongzue'
  51. email = 'myzcxhh@live.cn'
  52. }
  53. }
  54. // Version control info, if you're using GitHub, follow the format as seen here
  55. scm {
  56. //修改成你的Git地址:
  57. connection = 'scm:git:github.com/kongzue/DialogX.git'
  58. developerConnection = 'scm:git:ssh://github.com/kongzue/DialogX.git'
  59. //分支地址:
  60. url = 'https://github.com/kongzue/DialogX/tree/master'
  61. }
  62. // A slightly hacky fix so that your POM will include any transitive dependencies
  63. // that your library builds upon
  64. withXml {
  65. def dependenciesNode = asNode().appendNode('dependencies')
  66. project.configurations.implementation.allDependencies.each {
  67. def dependencyNode = dependenciesNode.appendNode('dependency')
  68. dependencyNode.appendNode('groupId', it.group)
  69. dependencyNode.appendNode('artifactId', it.name)
  70. dependencyNode.appendNode('version', it.version)
  71. }
  72. }
  73. }
  74. }
  75. }
  76. repositories {
  77. // The repository to publish to, Sonatype/MavenCentral
  78. maven {
  79. // This is an arbitrary name, you may also use "mavencentral" or
  80. // any other name that's descriptive for you
  81. name = "DialogX"
  82. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  83. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  84. // You only need this if you want to publish snapshots, otherwise just set the URL
  85. // to the release repo directly
  86. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  87. // The username and password we've fetched earlier
  88. credentials {
  89. username ossrhUsername
  90. password ossrhPassword
  91. }
  92. }
  93. }
  94. }
  95. signing {
  96. sign publishing.publications
  97. }