You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

artifacts.gradle 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. if (project.plugins.hasPlugin('com.android.library')) {
  2. android.libraryVariants.all { variant ->
  3. Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
  4. group = 'artifact'
  5. description "Generates Javadoc for $variant.name"
  6. // Source files from the variant
  7. source = variant.javaCompiler.source
  8. // Classpath from the variant + android.jar
  9. String androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
  10. classpath = variant.javaCompiler.classpath + files(androidJar)
  11. // Charset
  12. options.encoding 'UTF-8'
  13. options.charSet 'UTF-8'
  14. // Show author and version
  15. options.author true
  16. options.version true
  17. // ignore R
  18. options.addStringOption('Xdoclint:none R.java', '-quiet')
  19. // The Android online reference doesn't include package-list, so we have to use the local one
  20. String packageListRef = "${android.sdkDirectory}/docs/reference/"
  21. options.linksOffline 'http://d.android.com/reference/', packageListRef
  22. // Additional links for any RxJava references
  23. options.links 'http://reactivex.io/RxJava/javadoc/'
  24. // Exclude generated files
  25. exclude '**/BuildConfig.java'
  26. exclude '**/R.java'
  27. // Output to a unique javadoc folder per variant
  28. destinationDir = new File(project.docsDir, "javadoc-$variant.name")
  29. if (JavaVersion.current().isJava8Compatible()) {
  30. options.addStringOption('Xdoclint:none', '-quiet')
  31. }
  32. }
  33. // For official releasese, don't prefix the name so the artifact is published correctly
  34. // (Can't seem to modify it for publishing, for whatever reason...)
  35. String classifierPrefix = (variant.name == 'release') ? '' : "$variant.name-"
  36. Task javadocJarTask = task("generate${variant.name.capitalize()}JavadocJar", type: Jar, dependsOn: javadocTask) {
  37. group = 'artifact'
  38. description = "Generates Javadoc jar for $variant.name"
  39. classifier = "${classifierPrefix}javadoc"
  40. from javadocTask.destinationDir
  41. }
  42. Task sourcesJarTask = task("generate${variant.name.capitalize()}SourcesJar", type: Jar) {
  43. group = 'artifact'
  44. description = "Generates sources jar for $variant.name"
  45. classifier = "${classifierPrefix}sources"
  46. from variant.javaCompiler.source
  47. }
  48. if (variant.name == 'release') {
  49. // There's a lot of "magic" around the archives configuration; easier
  50. // just to embrace it rather than try to configure around it
  51. artifacts {
  52. archives javadocJarTask, sourcesJarTask
  53. }
  54. task('syncJavadoc', type: Sync, dependsOn: javadocTask) {
  55. from javadocTask.destinationDir
  56. into rootProject.file('docs')
  57. }
  58. }
  59. else {
  60. // Create a configuration we can publish from for each variant
  61. String configurationName = "archives${variant.name.capitalize()}"
  62. configurations.create(configurationName)
  63. artifacts.add configurationName, javadocJarTask
  64. artifacts.add configurationName, sourcesJarTask
  65. }
  66. }
  67. }