Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. apply plugin: 'maven-publish'
  2.  
  3. def androidExtension = project.extensions.findByName("android")
  4. if (androidExtension.hasProperty('libraryVariants')) {
  5. androidExtension.libraryVariants.all { final variant ->
  6. task("${variant.name}Javadoc", type: Javadoc) {
  7. description "Generates Javadoc for ${variant.name}."
  8. failOnError = false
  9. source = variant.javaCompile.source
  10. classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
  11. exclude '**/BuildConfig.java'
  12. exclude '**/R.java'
  13. }
  14. }
  15. }
  16. task androidJavadocsJar(type: Jar, dependsOn: 'releaseJavadoc') {
  17. classifier = 'javadoc'
  18. from {
  19. releaseJavadoc.destinationDir
  20. }
  21. }
  22. task androidSourcesJar(type: Jar) {
  23. classifier = 'sources'
  24. from android.sourceSets.main.java.srcDirs
  25. }
  26.  
  27. publishing {
  28. publications {
  29. release(MavenPublication) {
  30. groupId project.group
  31. artifactId project.name
  32. version project.version
  33.  
  34. artifact bundleRelease
  35. artifact androidJavadocsJar
  36. artifact androidSourcesJar
  37.  
  38.  
  39. pom.withXml {
  40. // List all compile dependencies and write to POM
  41. final Node dependenciesNode = asNode().appendNode('dependencies')
  42. final compileConfiguration = configurations.getByName('compile')
  43. compileConfiguration.allDependencies.each { final Dependency dependency ->
  44. final def noGroup = dependency.group == null
  45. final def noVersion = dependency.version == null
  46. final def noName = dependency.name == null
  47. final def invalidName = dependency.name == "unspecified"
  48. final def invalidDependency = noGroup || noVersion || noName || invalidName
  49. if (invalidDependency) {
  50. // ignore invalid dependencies
  51. return
  52. }
  53. final def dependencyFiles = compileConfiguration.files(dependency)
  54. final def firstFile = dependencyFiles.first()
  55. final def firstFileName = firstFile.name
  56. final def firstFileNameExtension = firstFileName.substring(firstFileName.lastIndexOf(".") + 1)
  57.  
  58. final dependencyNode = dependenciesNode.appendNode('dependency')
  59. dependencyNode.appendNode('groupId', dependency.group)
  60. dependencyNode.appendNode('artifactId', dependency.name)
  61. dependencyNode.appendNode('version', dependency.version)
  62. dependencyNode.appendNode('type', firstFileNameExtension)
  63.  
  64. if (!dependency.transitive) {
  65. // If this dependency is transitive, we should force exclude all its dependencies them from the POM
  66. final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
  67. exclusionNode.appendNode('groupId', '*')
  68. exclusionNode.appendNode('artifactId', '*')
  69. } else if (!dependency.properties.excludeRules.empty) {
  70. // Otherwise add specified exclude rules
  71. final exclusionsNode = dependencyNode.appendNode('exclusions')
  72. dependency.properties.excludeRules.each { final ExcludeRule rule ->
  73. final exclusionNode = exclusionsNode.appendNode('exclusion')
  74. exclusionNode.appendNode('groupId', rule.group ?: '*')
  75. exclusionNode.appendNode('artifactId', rule.module ?: '*')
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. repositories {
  83. maven {
  84. url "$buildDir/repo"
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement