gradle-mvn-push.gradle 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 2013 Chris Banes
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * This file is from:
  18. * https://github.com/chrisbanes/gradle-mvn-push/blob/master/gradle-mvn-push.gradle
  19. */
  20. apply plugin: 'maven-publish'
  21. apply plugin: 'signing'
  22. version = VERSION_NAME
  23. group = GROUP
  24. def isReleaseBuild() {
  25. return VERSION_NAME.contains("SNAPSHOT") == false
  26. }
  27. def getReleaseRepositoryUrl() {
  28. return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
  29. : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  30. }
  31. def getSnapshotRepositoryUrl() {
  32. return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
  33. : "https://oss.sonatype.org/content/repositories/snapshots/"
  34. }
  35. def getRepositoryUsername() {
  36. return hasProperty('nexusUsername') ? nexusUsername : ""
  37. }
  38. def getRepositoryPassword() {
  39. return hasProperty('nexusPassword') ? nexusPassword : ""
  40. }
  41. def configurePom(pom) {
  42. pom.name = POM_NAME
  43. pom.packaging = POM_PACKAGING
  44. pom.description = POM_DESCRIPTION
  45. pom.url = POM_URL
  46. pom.scm {
  47. url = POM_SCM_URL
  48. connection = POM_SCM_CONNECTION
  49. developerConnection = POM_SCM_DEV_CONNECTION
  50. }
  51. pom.licenses {
  52. license {
  53. name = POM_LICENCE_NAME
  54. url = POM_LICENCE_URL
  55. distribution = POM_LICENCE_DIST
  56. }
  57. }
  58. pom.developers {
  59. developer {
  60. id = POM_DEVELOPER_ID
  61. name = POM_DEVELOPER_NAME
  62. }
  63. }
  64. }
  65. afterEvaluate { project ->
  66. publishing {
  67. repositories {
  68. maven {
  69. def releasesRepoUrl = getReleaseRepositoryUrl()
  70. def snapshotsRepoUrl = getSnapshotRepositoryUrl()
  71. url = isReleaseBuild() ? releasesRepoUrl : snapshotsRepoUrl
  72. credentials(PasswordCredentials) {
  73. username = getRepositoryUsername()
  74. password = getRepositoryPassword()
  75. }
  76. }
  77. }
  78. }
  79. if (project.getPlugins().hasPlugin('com.android.application') ||
  80. project.getPlugins().hasPlugin('com.android.library')) {
  81. task androidJavadocs(type: Javadoc) {
  82. source = android.sourceSets.main.java.source
  83. classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
  84. excludes = ['**/*.kt']
  85. }
  86. task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
  87. classifier = 'javadoc'
  88. from androidJavadocs.destinationDir
  89. }
  90. task androidSourcesJar(type: Jar) {
  91. classifier = 'sources'
  92. from android.sourceSets.main.java.source
  93. }
  94. }
  95. if (JavaVersion.current().isJava8Compatible()) {
  96. allprojects {
  97. tasks.withType(Javadoc) {
  98. options.addStringOption('Xdoclint:none', '-quiet')
  99. }
  100. }
  101. }
  102. if (JavaVersion.current().isJava9Compatible()) {
  103. allprojects {
  104. tasks.withType(Javadoc) {
  105. options.addBooleanOption('html5', true)
  106. }
  107. }
  108. }
  109. artifacts {
  110. if (project.getPlugins().hasPlugin('com.android.application') ||
  111. project.getPlugins().hasPlugin('com.android.library')) {
  112. archives androidSourcesJar
  113. archives androidJavadocsJar
  114. }
  115. }
  116. android.libraryVariants.all { variant ->
  117. tasks.androidJavadocs.doFirst {
  118. classpath += files(variant.javaCompileProvider.get().classpath.files.join(File.pathSeparator))
  119. }
  120. }
  121. publishing.publications.all { publication ->
  122. publication.groupId = GROUP
  123. publication.version = VERSION_NAME
  124. publication.artifact androidSourcesJar
  125. publication.artifact androidJavadocsJar
  126. configurePom(publication.pom)
  127. }
  128. signing {
  129. publishing.publications.all { publication ->
  130. sign publication
  131. }
  132. }
  133. }