build.gradle 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. apply plugin: 'maven-publish'
  2. apply plugin: 'signing'
  3. // 此处不需修改,下面会读取 local.properties 中配置的信息
  4. ext["PUBLISH_VERSION"] = '' //发布的版本
  5. ext["PUBLISH_GROUP_ID"] = '' //分组ID
  6. ext["PUBLISH_ARTIFACT_ID"] = '' //
  7. ext["signing.keyId"] = '' //签名的密钥后8位
  8. ext["signing.password"] = '' //签名设置的密码
  9. ext["signing.secretKeyRingFile"] = '' //生成的secring.gpg文件目录
  10. ext["ossrhUsername"] = '' //sonatype用户名
  11. ext["ossrhPassword"] = '' //sonatype密码
  12. // 遍历赋值
  13. File secretPropsFile = project.rootProject.file('local.properties')
  14. if (secretPropsFile.exists()) {
  15. println "Found secret props file, loading props"
  16. Properties p = new Properties()
  17. p.load(new FileInputStream(secretPropsFile))
  18. p.each { name, value ->
  19. ext[name] = value
  20. }
  21. ext["PUBLISH_ARTIFACT_ID"]="intermodal-release"
  22. ext["PUBLISH_VERSION"]="1.0.1"
  23. } else {
  24. println "No props file, loading env vars"
  25. }
  26. afterEvaluate {
  27. publishing {
  28. repositories {
  29. maven {
  30. //推送至远端的中央仓库,一旦发布release中央仓库版本,旧版本无法修改
  31. //一般都在 暂存库 中进行测试,然后确认无误后再发布到 release中央仓库
  32. allowInsecureProtocol = false
  33. name = PUBLISH_ARTIFACT_ID
  34. // 暂存库
  35. def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
  36. // 快照库(版本名以 SNAPSHOT 结尾,就推送至快照库)
  37. def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
  38. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  39. credentials {
  40. username ossrhUsername
  41. password ossrhPassword
  42. }
  43. }
  44. maven {
  45. // 推送至本地存储库,本机测试的时候可以用
  46. allowInsecureProtocol = false
  47. name = 'Local'
  48. url = uri('../ZrgkLocalRepo')
  49. }
  50. }
  51. publications {
  52. release(MavenPublication) {
  53. println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION")
  54. groupId PUBLISH_GROUP_ID
  55. artifactId PUBLISH_ARTIFACT_ID
  56. version PUBLISH_VERSION
  57. // 生成的 aar 路径,修改成自己的aar地址名称
  58. // artifact "$buildDir/outputs/aar/${project.name}-release.aar"
  59. artifact "F:\\Work_Space\\Wechat_workSpace\\duoduan_reader_test\\chajian\\android\\LocalRepo\\intermodal-release\\intermodal-release.aar"
  60. // 如果需要将源代码一起打包进aar,就打开此注释。
  61. //artifact androidSourcesJar
  62. pom {
  63. name = PUBLISH_ARTIFACT_ID
  64. description = 'efunboxMaven' //项目描述
  65. url = 'https://github.com/FailedToRead/AndroidMaven' //项目github链接
  66. licenses {
  67. license {
  68. //协议类型,一般默认Apache License2.0的话不用改:
  69. name = 'The Apache License, Version 2.0'
  70. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  71. }
  72. }
  73. developers {
  74. developer {
  75. // 修改自己对应的用户名、邮箱
  76. id = 'FailedToRead' //你的sonatype用户名
  77. name = 'FailedToRead' //你的sonatype用户名
  78. email = 'zhangoq9@gmail.com' //你的sonatype注册邮箱
  79. }
  80. }
  81. // Version control info, if you're using GitHub, follow the format as seen here
  82. scm {
  83. //修改成你的Git地址:
  84. connection = 'scm:https://github.com/FailedToRead/AndroidMaven.git'
  85. developerConnection = 'scm:https://github.com/FailedToRead/AndroidMaven.git'
  86. //分支地址:
  87. url = 'https://github.com/FailedToRead/AndroidMaven/tree/test'
  88. }
  89. // pom.withXml {
  90. // def dependenciesNode = asNode().appendNode('dependencies')
  91. // configurations.implementation.allDependencies.each {
  92. // // 避免出现空节点或 artifactId=unspecified 的节点
  93. // if (it.group != null && (it.name != null && "unspecified" != it.name) && it.version != null) {
  94. // println "dependency=${it.toString()}"
  95. // def dependencyNode = dependenciesNode.appendNode('dependency')
  96. // dependencyNode.appendNode('groupId', it.group)
  97. // dependencyNode.appendNode('artifactId', it.name)
  98. // dependencyNode.appendNode('version', it.version)
  99. // dependencyNode.appendNode('scope', 'implementation')
  100. //
  101. // }
  102. // }
  103. // }
  104. }
  105. }
  106. }
  107. }
  108. signing {
  109. sign publishing.publications
  110. }
  111. }
  112. configurations.maybeCreate("default")
  113. artifacts.add("default", file('intermodal-release.aar'))