无法让 dokka 在 gradle/android 项目上生成 kotlin 文档

Posted

技术标签:

【中文标题】无法让 dokka 在 gradle/android 项目上生成 kotlin 文档【英文标题】:Can't get dokka to generate kotlin docs on gradle/android project 【发布时间】:2016-05-29 23:05:11 【问题描述】:

我正在关注https://github.com/Kotlin/dokka 中的 gradle 插件部分。

我还尝试了 https://github.com/JetBrains/kotlin-examples/tree/master/gradle/dokka-gradle-example 中的 dokka-gradle-example 示例。

我使用的版本是:

android: '23.1.1'
dokka: '0.9.6'
gradle-android-plugin: '1.5.0'
kotlin: '1.0.0-rc-1036'

但我也尝试了从 0.9 到 0.9.7 的 Dokka 版本。

输出的相关部分是:

...

:app:dokka FAILED
:app:dokka (Thread[Daemon worker Thread 9,5,main]) completed. Took 0.766 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dokka'.
> com.intellij.mock.MockComponentManager.getPicoContainer()Lorg/picocontainer/MutablePicoContainer;

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:dokka'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: java.lang.NoSuchMethodError: com.intellij.mock.MockComponentManager.getPicoContainer()Lorg/picocontainer/MutablePicoContainer;
    at org.jetbrains.dokka.AnalysisEnvironment.createCoreEnvironment(AnalysisEnvironment.kt:78)
    at org.jetbrains.dokka.Utilities.DokkaModule.configure(DokkaModule.kt:50)
    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
    at com.google.inject.spi.Elements.getElements(Elements.java:110)
    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
    at com.google.inject.Guice.createInjector(Guice.java:96)
    at com.google.inject.Guice.createInjector(Guice.java:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at org.jetbrains.dokka.DokkaGenerator.generate(main.kt:160)
    at org.jetbrains.dokka.gradle.DokkaTask.generate(main.kt:63)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 54 more


BUILD FAILED

更新

我包括构建文件:

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript 
    repositories 
        jcenter()
    

    ext.versions = [
            android: '23.1.1',
            anko: '0.8.2',
            dokka: '0.9.6',
            gradleAndroid: '1.5.0',
            kotlin: '1.0.0',
            spek: '0.1.194'
    ]

    dependencies 
        classpath "com.android.tools.build:gradle:$versions.gradleAndroid"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    


allprojects 
    repositories 
        jcenter()
    


模块app/build.gradle

buildscript 
    repositories 
        mavenLocal()
        mavenCentral()
        jcenter()
    

    dependencies 
        classpath "com.android.tools.build:gradle:$versions.gradleAndroid"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:$versions.dokka"
    



apply plugin: 'org.jetbrains.dokka'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

repositories 
    jcenter()
    maven 
        url "http://repository.jetbrains.com/all"
    


android 
    sourceCompatibility = 1.5

    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig 
        applicationId "com.example"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    

    buildTypes 
        release 
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        

        buildTypes 
            debug 
                testCoverageEnabled true
            
        
    

    sourceSets 
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
    


dependencies 
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:$versions.android"
    compile "com.android.support:design:$versions.android"
    compile "com.android.support:cardview-v7:$versions.android"

    compile "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"

    compile "org.jetbrains.anko:anko-common:$versions.anko"
    compile "org.jetbrains.anko:anko-sdk15:$versions.anko"
    compile "org.jetbrains.anko:anko-support-v4:$versions.anko"
    compile "org.jetbrains.anko:anko-design:$versions.anko"
    compile "org.jetbrains.anko:anko-appcompat-v7:$versions.anko"
    compile "org.jetbrains.anko:anko-cardview-v7:$versions.anko"
    compile "org.jetbrains.anko:anko-recyclerview-v7:$versions.anko"
    compile "org.jetbrains.anko:anko-gridlayout-v7:$versions.anko"

    testCompile "org.jetbrains.spek:spek:$versions.spek"
    testCompile "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"


dokka 

【问题讨论】:

文档指出:您必须在 kotlin 和 com.android.application 插件之后应用 dokka 插件。尝试更改顺序。 【参考方案1】:

[更新] 这被报告为用https://github.com/Kotlin/dokka/pull/64 修复。


问题是当前版本的 dokka 无法获取 build.gradle 文件的 android 块中定义的 sourceSets

要解决这个问题直到它被修复(我将在 dokka Github 存储库上创建一个问题),您可以在 android 块之外复制 sourceSets,以便 dokka 可以解决它。

android 
  ...

  sourceSets 
    main.java.srcDirs += 'src/main/kotlin'
    test.java.srcDirs += 'src/test/kotlin'
  


sourceSets 
  main.java.srcDirs += 'src/main/kotlin'
  test.java.srcDirs += 'src/test/kotlin

我遇到了同样的问题,这为我解决了。

【讨论】:

请您提供指向 GitHub 问题 @eski 的链接。由于添加了buildType,我在运行 dokka 任务时遇到问题。 原来是github.com/Kotlin/dokka/issues/61,但现在看来已经修复了【参考方案2】:

试用 Kotlin 1.0.0 版本,使用最新的 Dokka 0.9.7。你那里不匹配。 Gradle 的 Kotlin 插件和 Dokka 版本必须兼容。如果您继续有冲突,则可能是您有另一个插件与这些冲突。

Dokka 0.9.8 或更新版本不再与 Kotlin 编译器版本冲突。它现在包含需要嵌入的阴影依赖项以避免冲突。

【讨论】:

感谢您的回答。我已经更新到 kotlin 1.0.0 和 Dokka 0.9.7,但它仍然无法正常工作。另外,我删除了所有其他插件,只保留ankodokkaspek,但我仍然无法让它工作。我现在将尝试在一个单独的项目中减少anko @TiagoReul 没有更多的构建信息,很难说发生了什么。您可能需要尝试 Kotlin 论坛讨论,或在 Slack 中。 和 Kotlin 1.0.3 和 Dokka 0.9.6。啊。【参考方案3】:

dokka 文档单独处理 Android:

如果您使用的是 Android,则有一个单独的 gradle 插件。只需确保在 com.android.library 和 kotlin-android 之后应用插件即可。

尝试使用classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$versions.dokka" 作为依赖项并将apply plugin: 'org.jetbrains.dokka-android' 添加到插件列表的末尾,从开头删除apply plugin: 'org.jetbrains.dokka'

编辑:这应该是固定的,如下面的评论所述。

【讨论】:

自 v0.10.0 起,android 插件已与默认插件合并。【参考方案4】:

您可以在没有 Dokka 插件的情况下生成 Dokka 文档...使用GradleMavenPush,它有task androidDokka(type: Exec, dependsOn: dokkaInitializer)task coreDokka(type: Exec, dependsOn: dokkaInitializer)

apply from: 'https://raw.github.com/Vorlonsoft/GradleMavenPush/master/maven-push.gradle'

别忘了设置JAVADOC_BY_DOKKA = true

【讨论】:

以上是关于无法让 dokka 在 gradle/android 项目上生成 kotlin 文档的主要内容,如果未能解决你的问题,请参考以下文章

KDoc / Dokka:忽略子类中的继承方法

如何向 Kotlin Dokka 文档添加页脚?

Dokka - 跳过为默认的 android 包生成 javadoc

使用Dokka为Kotlin代码生成KDoc

C - Ekka Dokka

如何使用 dokka 生成用于存储库上传的 javadoc jar?