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