publish.gradle 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. apply plugin: 'maven-publish'
  2. apply plugin: 'signing'
  3. ext {
  4. PUBLISH_GROUP_ID = 'io.github.suyghur.dolin'
  5. PUBLISH_ARTIFACT_ID = 'crashlytics'
  6. PUBLISH_VERSION = '1.0.1-alpha'
  7. }
  8. Properties properties = new Properties()
  9. properties.load(project.rootProject.file('local.properties').newDataInputStream())
  10. def ossrhUsername = properties.getProperty("SonaType.user")
  11. def ossrhPassword = properties.getProperty("SonaType.pwd")
  12. task androidSourcesJar(type: Jar) {
  13. archiveClassifier.set('source')
  14. if (project.plugins.findPlugin('com.android.library')) {
  15. from android.sourceSets.main.java.srcDirs
  16. } else {
  17. form sourceSets.main.java.srcDirs
  18. }
  19. exclude "**/R.class"
  20. exclude "**/BuildConfig.class"
  21. }
  22. publishing {
  23. publications {
  24. release(MavenPublication) {
  25. // The coordinates of the library, being set from variables that
  26. // we'll set up in a moment
  27. groupId PUBLISH_GROUP_ID
  28. artifactId PUBLISH_ARTIFACT_ID
  29. version PUBLISH_VERSION
  30. // Two artifacts, the `aar` and the sources
  31. artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
  32. artifact androidSourcesJar
  33. // Self-explanatory metadata for the most part
  34. pom {
  35. name = "${PUBLISH_GROUP_ID}:${PUBLISH_ARTIFACT_ID}"
  36. description = 'a log framework of Android'
  37. // If your project has a dedicated site, use its URL here
  38. url = 'https://github.com/Suyghur/Dolin'
  39. licenses {
  40. license {
  41. //协议类型,一般默认Apache License2.0的话不用改:
  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 = 'Suyghur'
  49. name = 'Suyghur'
  50. email = 'suyghurmjp@outlook.com'
  51. }
  52. }
  53. // Version control info, if you're using GitHub, follow the format as seen here
  54. scm {
  55. //修改成你的Git地址:
  56. connection = 'scm:git:github.com/Suyghur/Dolin.git'
  57. developerConnection = 'scm:git:ssh://github.com/Suyghur/Dolin.git'
  58. //分支地址:
  59. url = 'https://github.com/Suyghur/Dolin'
  60. }
  61. // A slightly hacky fix so that your POM will include any transitive dependencies
  62. // that your library builds upon
  63. withXml {
  64. def dependenciesNode = asNode().appendNode('dependencies')
  65. project.configurations.implementation.allDependencies.each {
  66. def dependencyNode = dependenciesNode.appendNode('dependency')
  67. dependencyNode.appendNode('groupId', it.group)
  68. dependencyNode.appendNode('artifactId', it.name)
  69. dependencyNode.appendNode('version', it.version)
  70. }
  71. }
  72. }
  73. }
  74. }
  75. repositories {
  76. // The repository to publish to, Sonatype/MavenCentral
  77. maven {
  78. // This is an arbitrary name, you may also use "mavencentral" or
  79. // any other name that's descriptive for you
  80. name = "mavencentral"
  81. def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
  82. def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
  83. // You only need this if you want to publish snapshots, otherwise just set the URL
  84. // to the release repo directly
  85. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  86. // The username and password we've fetched earlier
  87. credentials {
  88. username ossrhUsername
  89. password ossrhPassword
  90. }
  91. }
  92. }
  93. }
  94. signing {
  95. sign publishing.publications
  96. }
  97. publishReleasePublicationToMavencentralRepository.dependsOn(assemble)