Android studio / Gradle javadoc task

后端 未结 3 886

I\'ve been struggling to setup a gradle task to generate Javadocs for my Android library, but when there are external dependencies to other libraries, doc generation fails.

相关标签:
3条回答
  • 2021-01-01 19:48

    I use a gradle task that just executes a bash script file, with a single (pretty long) javadoc command.

    What you can do is run the Javadoc generation from Android Studio once, then copy the executed javadoc command from the Studio log, with all the right parameters, and automate the execution of the same command in your gradle.

    0 讨论(0)
  • 2021-01-01 19:52

    The tool to generate java style documentation is called javadoc and it comes installed in every JDK. You can configure which classes or packages you want to be included, which ones should be excluded and many other options. Type javadoc in a terminal where a JDK is available and you'll get an idea. See also https://docs.oracle.com/javase/9/javadoc/javadoc.htm#JSJAV-GUID-7A344353-3BBF-45C4-8B28-15025DDCC643

    After you get to your optimal configuration, you can include a javadoc step in your CI.

    0 讨论(0)
  • 2021-01-01 20:09

    Maybe you have got the solution to this. Just in case not, below is how I generate API doc for my Jenkins CI.

    task generateApiDoc() {
        group "reporting"
        description "Generates Javadoc."
    }
    
    android.libraryVariants.all { variant ->
        // Only consider release 
        if (variant.buildType.name == "release") {
            def task = project.tasks.create("generate${variant.name.capitalize()}Javadoc", Javadoc) {
                group "ApiDoc"
                description "Generates Javadoc for $variant.name."
    
                // Source files from the variant
                source = variant.javaCompiler.source
                // Classpath from the variant + android.jar
                classpath = variant.javaCompiler.classpath + files(prj.android.getBootClasspath()) + files("$buildDir/intermediates/classes/release")
    
                /* add the excluded packages */
                exclude "**/R**"
                exclude "**/BuildConfig*"
    
                options.windowTitle = "My Library"
                options.memberLevel = JavadocMemberLevel.PROTECTED
                options.linkSource false
                options.author = true
                //options.links("http://docs.oracle.com/javase/7/docs/api/", "http://d.android.com/reference");
    
                failOnError false
            }
    
            task.dependsOn assemble
    
            generateApiDoc.dependsOn task
        }
    }
    

    Then run below gradle commands to get your api doc in place of "$buildDir/docs".

    ./gradlew assembleRelease
    ./gradlew generateApiDoc
    

    Edit for Gradle Plugin 3.4.1

    android.libraryVariants.all { variant ->
    
        def task = project.tasks.create("generate${variant.name.capitalize()}Javadoc", Javadoc) {
            title "API Documentation (${project.android.defaultConfig.versionName})"
            group "ApiDoc"
            description "Generates Javadoc for $variant.name."
    
            // Source files from the variant
            source = variant.sourceSets.collect { it.java.sourceFiles }.inject { m, i -> m + i }
    
            // To fix issue: Error: Can not create variant 'android-lint' after configuration ': library: debugRuntimeElements' has been resolved
            doFirst {
                classpath = project.files(variant.javaCompileProvider.get().classpath.files,
                        project.android.getBootClasspath())
            }
    
            if (JavaVersion.current().isJava8Compatible()) {
                options.addStringOption('Xdoclint:none', '-quiet')
            }
    
            exclude "**/R"
            exclude "**/R.**"
            exclude "**/R\$**"
            exclude "**/BuildConfig*"
    
            if (JavaVersion.current().isJava8Compatible()) {
                options.addStringOption('Xdoclint:none', '-quiet')
            }
    
            options.windowTitle = "API Documentation (${project.android.defaultConfig.versionName})"
            options.memberLevel = JavadocMemberLevel.PROTECTED
            options.linkSource false
            options.author = false
    
            failOnError true
        }
    
        task.dependsOn "assemble${variant.name.capitalize()}"
        generateApiDoc.dependsOn task
    }
    
    
    0 讨论(0)
提交回复
热议问题