David Ferrand
David Ferrand

Reputation: 5470

Exclude aidl files from Javadoc task with Gradle

I'm currently discovering Android Studio and Gradle and migrating all the build chain of my project from bash scripts to Gradle configurations. It's probably going to be awesome in the end, but meanwhile I'm struggling.

What I want to do now is quite simple. I have a standard rule to generate Javadoc from my source (I took this snippet from http://snowdream.github.io/blog/android/2013/11/01/how-to-generate-javadocs-with-android-gradle-plugin/):

android.libraryVariants.all { variant ->
    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
        source = variant.javaCompile.source
        def androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"

        classpath = files(variant.javaCompile.classpath.files, androidJar)
        options {
            links "http://docs.oracle.com/javase/7/docs/api/"
            linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference"
        }
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
    }
}

But my project also contains AIDL files and I don't want these aidl files (nor the .java files generated from them) to be included to the Javadoc.

I tried the rule:

exclude "**/$buildDir/**"

... and I tried a thousand others, but none works and my interfaces and Stub are processed into HTML files.

I beg for your help! Thanks a lot.

Upvotes: 1

Views: 1533

Answers (1)

David Ferrand
David Ferrand

Reputation: 5470

After hours of research about how Gradle and Groovy work, the best way I found is:

exclude {
  it.file.path.contains('aidl')
}

However, I'm still unsatisfied. I do feel something less brutal could be done using variant.aidlCompile.sourceOutputDir that points to the Java files generated by AIDL. But I could not compare the iterated elements in the Closure to this File, or FileTree, or whatever shape I give it...

EDIT:

After further research, another method is to hide the interfaces defined in AIDL using a custom Doclet that supports @hide tag (like Doclava). I preferred this method because it doesn't cause errors during Javadoc generation.

Upvotes: 2

Related Questions