publish-mavencentral.gradle 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 Open Source Project'
  38. // If your project has a dedicated site, use its URL here
  39. url = 'https://github.com/kongzue/DialogX'
  40. licenses {
  41. license {
  42. name = 'The Apache License, Version 2.0'
  43. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  44. }
  45. }
  46. developers {
  47. developer {
  48. id = 'kongzue'
  49. name = 'kongzue'
  50. email = 'myzcxhh@live.cn'
  51. }
  52. }
  53. // Version control info, if you're using GitHub, follow the format as seen here
  54. scm {
  55. connection = 'scm:git:github.com/kongzue/DialogX.git'
  56. developerConnection = 'scm:git:ssh://github.com/kongzue/DialogX.git'
  57. url = 'https://github.com/kongzue/DialogX/tree/master'
  58. }
  59. // A slightly hacky fix so that your POM will include any transitive dependencies
  60. // that your library builds upon
  61. withXml {
  62. def dependenciesNode = asNode().appendNode('dependencies')
  63. project.configurations.implementation.allDependencies.each {
  64. def dependencyNode = dependenciesNode.appendNode('dependency')
  65. dependencyNode.appendNode('groupId', it.group)
  66. dependencyNode.appendNode('artifactId', it.name)
  67. dependencyNode.appendNode('version', it.version)
  68. }
  69. }
  70. }
  71. }
  72. }
  73. repositories {
  74. // The repository to publish to, Sonatype/MavenCentral
  75. maven {
  76. // This is an arbitrary name, you may also use "mavencentral" or
  77. // any other name that's descriptive for you
  78. name = "DialogX"
  79. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  80. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  81. // You only need this if you want to publish snapshots, otherwise just set the URL
  82. // to the release repo directly
  83. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  84. // The username and password we've fetched earlier
  85. credentials {
  86. username ossrhUsername
  87. password ossrhPassword
  88. }
  89. }
  90. }
  91. }
  92. signing {
  93. sign publishing.publications
  94. }