当前位置 : 主页 > 手机开发 > 其它 >

使用多个库模块聚合Javadoc for Android项目

来源:互联网 收集:自由互联 发布时间:2021-06-22
我已经浏览了几乎整个互联网,寻找一种方法,如何将包含单独库模块的项目中的 Javadoc聚合到单个 Javadoc中. 有一个插件显然允许这样做: https://github.com/nebula-plugins/gradle-aggregate-javadocs-
我已经浏览了几乎整个互联网,寻找一种方法,如何将包含单独库模块的项目中的 Javadoc聚合到单个 Javadoc中.

有一个插件显然允许这样做:
https://github.com/nebula-plugins/gradle-aggregate-javadocs-plugin

但是,如果我运行插件指定的命令,Gradle会找到该任务并执行它但不会生成输出目录.

任何帮助如何从多个模块构建单个Javadoc非常感谢.

我设法让它在不久前工作,为迟到的回应道歉.可聚合Javadoc创建的解决方案如下:

>在项目中维护的每个子项目中,创建生成Javadoc的任务:

android.libraryVariants.all { variant ->

task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
    destinationDir = project.file("$project.projectDir/javadoc/$project.PROJECT_NAME") //Project name in the Project's gradle.properties
    title = "A title of my project - $project.PROJECT_VERSION_NAME" //Project version name in the Project's gradle.properties
    description "Generates Javadoc for $variant.name."
    source = variant.javaCompile.source
    ext.androidJar ="${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) + project.files(android.getBootClasspath().join(File.pathSeparator))
    options {
        memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC //change the modifier according to your needs
        links "http://docs.oracle.com/javase/8/docs/api/"
        linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
    }
    exclude '**/BuildConfig.java'
    exclude '**/R.java'
}

  task("bundle${variant.name.capitalize()}Javadoc", type: Jar) {
    baseName = "Compass API - ($version)"
    description "Bundles Javadoc into zip for $variant.name."
    classifier = "javadoc"
    from tasks["generate${variant.name.capitalize()}Javadoc"]
  }
}

上面的配置为子项目的每个buildVariant添加了一个Javadoc生成任务.此时,您可以通过键入单独为每个模块生成Javadoc

gradle :myRootProject:mySubproject:generateDebugJavadoc
gradle :myRootProject:mySubproject:generateReleaseJavadoc
gradle :myRootProject:mySubproject:generateMyFancyFlavourDebugJavadoc
gradle :myRootProject:mySubproject:generateMyFancyFlavourReleaseJavadoc

如果使用JRE 8,则以下配置将禁用doclint在Javadoc构建期间引发的错误(explanation in greater detail here)

if (JavaVersion.current().isJava8Compatible()) {
     tasks.withType(Javadoc) {
         // disable the crazy super-strict doclint tool in Java 8
         //noinspection SpellCheckingInspection
         options.addStringOption('Xdoclint:none', '-quiet')
     }
    }

>要将每个子模块的Javadoc聚合为单个子模块,请在build.gradle中创建一个插件,这将向子模块添加一个您感兴趣的部分Javadoc生成的任务:

class JavadocAggregationPlugin implements Plugin<Project> {
 static final String AGGREGATE_JAVADOCS_TASK_NAME = 'aggregateJavadocs'

 @Override
 void apply(Project project) {
     Project rootProject = project.rootProject
     rootProject.gradle.projectsEvaluated {
        Set<Project> librarySubprojects = getLibraryProjects(rootProject)
         if (!librarySubprojects.isEmpty()) {
            rootProject.task(AGGREGATE_JAVADOCS_TASK_NAME, type: Javadoc) {
                 description = 'Aggregates Javadoc API documentation of all subprojects.'
                 group = JavaBasePlugin.DOCUMENTATION_GROUP
                 dependsOn librarySubprojects.generateReleaseJavadoc //please note that generateReleaseJavadoc is the name of the separate Javadoc generation task in each library module

                 source librarySubprojects.generateReleaseJavadoc.source
                 destinationDir rootProject.file("$rootProject.buildDir/docs/javadoc") //Javadoc destination directory
                 classpath = rootProject.files(librarySubprojects.generateReleaseJavadoc.classpath)
             }
         }
     }
 }

private Set<Project> getLibraryProjects(Project rootProject) {
    rootProject.subprojects.findAll { subproject -> subproject.plugins.findPlugin("com.android.library") } //In this case every library module is selected
}
}

最后,将插件包含在插件定义下方Project的build.gradle中的gradle配置中.

apply plugin: JavadocAggregationPlugin

>通过执行此操作并重建gradle的配置,您应该能够通过cli键入以下命令在指定目录中创建聚合Javadoc:

gradle aggregateJavadocs

希望有所帮助.

有用的链接:Android Gradle DSL

网友评论