android_publish_mavencentral.gradle 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. if (versions == null || versions.publish_version == null) {
  2. throw new IllegalStateException("Unable to reference publish_version!")
  3. } else if (module_group == null || module_name == null) {
  4. throw new IllegalStateException("Must provide module_group and module_name!")
  5. }
  6. apply plugin: 'maven-publish'
  7. apply plugin: 'signing'
  8. task androidSourcesJar(type: Jar) {
  9. archiveClassifier.set('sources')
  10. if (project.plugins.findPlugin("com.android.library")) {
  11. // For Android libraries
  12. from android.sourceSets.main.java.srcDirs
  13. from android.sourceSets.main.kotlin.srcDirs
  14. } else {
  15. // For pure Kotlin libraries, in case you have them
  16. from sourceSets.main.java.srcDirs
  17. from sourceSets.main.kotlin.srcDirs
  18. }
  19. }
  20. artifacts {
  21. archives androidSourcesJar
  22. }
  23. group = module_group
  24. version = versions.publish_version
  25. // Default values
  26. ext["signing.keyId"] = ''
  27. ext["signing.password"] = ''
  28. ext["signing.secretKeyRingFile"] = ''
  29. ext["ossrhUsername"] = ''
  30. ext["ossrhPassword"] = ''
  31. ext["sonatypeStagingProfileId"] = ''
  32. File secretPropsFile = project.rootProject.file('local.properties')
  33. if (secretPropsFile.exists()) {
  34. Properties p = new Properties()
  35. new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
  36. p.each { name, value -> ext[name] = value }
  37. } else {
  38. ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
  39. ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
  40. ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
  41. ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
  42. ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
  43. ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
  44. }
  45. publishing {
  46. publications {
  47. release(MavenPublication) {
  48. // The coordinates of the library, being set from variables that
  49. // we'll set up later
  50. groupId module_group
  51. artifactId module_name
  52. version versions.publish_version
  53. // Two artifacts, the `aar` (or `jar`) and the sources
  54. if (project.plugins.findPlugin("com.android.library")) {
  55. artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
  56. } else {
  57. artifact("$buildDir/libs/${project.getName()}-${version}.jar")
  58. }
  59. artifact androidSourcesJar
  60. // Mostly self-explanatory metadata
  61. pom {
  62. packaging 'aar'
  63. name = module_name
  64. description = '😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.'
  65. url = 'https://github.com/afollestad/material-dialogs'
  66. licenses {
  67. license {
  68. name = 'Apache 2.0 License'
  69. url = 'https://github.com/afollestad/material-dialogs/blob/main/LICENSE.md'
  70. }
  71. }
  72. developers {
  73. developer {
  74. id = 'afollestad'
  75. name = 'Aidan Follestad'
  76. email = 'dont-email-me@af.codes'
  77. }
  78. // Add all other devs here...
  79. }
  80. // Version control info - if you're using GitHub, follow the format as seen here
  81. scm {
  82. connection = 'scm:git:github.com/afollestad/material-dialogs.git'
  83. developerConnection = 'scm:git:ssh://github.com/afollestad/material-dialogs.git'
  84. url = 'https://github.com/afollestad/material-dialogs/tree/main'
  85. }
  86. // A slightly hacky fix so that your POM will include any transitive dependencies
  87. // that your library builds upon
  88. withXml {
  89. def dependenciesNode = asNode().appendNode('dependencies')
  90. project.configurations.implementation.allDependencies.each {
  91. def dependencyNode = dependenciesNode.appendNode('dependency')
  92. dependencyNode.appendNode('groupId', it.group)
  93. dependencyNode.appendNode('artifactId', it.name)
  94. dependencyNode.appendNode('version', it.version)
  95. }
  96. }
  97. }
  98. }
  99. }
  100. // The repository to publish to, Sonatype/MavenCentral
  101. repositories {
  102. maven {
  103. // This is an arbitrary name, you may also use "mavencentral" or
  104. // any other name that's descriptive for you
  105. name = "sonatype"
  106. url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  107. credentials {
  108. username ossrhUsername
  109. password ossrhPassword
  110. }
  111. }
  112. }
  113. }
  114. signing {
  115. sign publishing.publications
  116. }
  117. afterEvaluate {
  118. publishReleasePublicationToSonatypeRepository.dependsOn assembleRelease
  119. }