Dokka: KotlinNullPointerException when running gradle task in kotlin2js project

Created on 31 Aug 2017  路  9Comments  路  Source: Kotlin/dokka

Hi!

I'm having problem running dokka task in a kotlin2js project.
Got kotlin.KotlinNullPointerException (no error message) here after:

18:12:56.616 [DEBUG] [org.gradle.api.Task] Dokka found AbstractKotlinCompile task: task ':compileKotlin2Js'

Stack trace:

kotlin.KotlinNullPointerException
  at org.jetbrains.dokka.ReflectDsl$CallOrPropAccess.v(ReflectDsl.kt:30)
  at org.jetbrains.dokka.ReflectDsl$CallOrPropAccess.get(ReflectDsl.kt:18)
  at org.jetbrains.dokka.gradle.DokkaTask.extractClasspathAndSourceRootsFromKotlinTasks(main.kt:216)
  at org.jetbrains.dokka.gradle.DokkaTask.access$extractClasspathAndSourceRootsFromKotlinTasks(main.kt:54)
  at org.jetbrains.dokka.gradle.DokkaTask$kotlinCompileBasedClasspathAndSourceRoots$2.invoke(main.kt:116)
  at org.jetbrains.dokka.gradle.DokkaTask$kotlinCompileBasedClasspathAndSourceRoots$2.invoke(main.kt:54)
  at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130)
  at org.jetbrains.dokka.gradle.DokkaTask.getKotlinCompileBasedClasspathAndSourceRoots$gradle_plugin_main(main.kt)
  at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
  at org.gradle.api.internal.project.taskfactory.TaskPropertyInfo$4.create(TaskPropertyInfo.java:99)
  at org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:217)
  at org.gradle.api.internal.project.taskfactory.TaskPropertyInfo.getValue(TaskPropertyInfo.java:97)
  at org.gradle.api.internal.project.taskfactory.TaskClassValidator.validate(TaskClassValidator.java:78)
  at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:41)
  at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
  at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
  at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
  at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
  at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
  at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
  at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:242)
  at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
  at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
  at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
  at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
  at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:235)
  at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:224)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:121)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:77)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:102)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:96)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:612)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:567)
  at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:96)
  at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
  at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
  at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)

Build file (based on this example) :

apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'com.moowork.node'

buildscript {
    ext.kotlin_version = '1.1.4-3'
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0'
        classpath 'org.jetbrains.dokka:dokka-gradle-plugin:0.9.15'
    }
}

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}

[compileKotlin2Js, compileTestKotlin2Js]*.configure {
    kotlinOptions.metaInfo = true
    kotlinOptions.sourceMap = true
    kotlinOptions.moduleKind = "commonjs"
}

task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
   from compileKotlin2Js.destinationDir

   configurations.testCompile.each {
       from zipTree(it.absolutePath).matching { include '*.js' }
   }

   into "${buildDir}/node_modules"
}

node { 
  download = true
}

dokka {
    outputFormat = 'html'
    outputDirectory = "${projectDir}/doc"
}

task installMocha(type: NpmTask) {
    args = ['install', 'mocha']
}

task runMocha(type: NodeTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, installMocha]) {
    script = file('node_modules/mocha/bin/mocha')
    args = [compileTestKotlin2Js.outputFile]
}

test.dependsOn runMocha

Gradle version: 4.0

bug

Most helpful comment

As a temporary workaround downgrading Dokka to version 0.9.14 resolves the issue.

All 9 comments

As a temporary workaround downgrading Dokka to version 0.9.14 resolves the issue.

Any other thoughts on when this will be resolved, or other workarounds? I am trying to use this on a multi-platform build with the 'suppress = true' option, so downgrading is not an option for me. Will the code work by just ignoring the exception and adding user supplied sources instead?

My workaround is to change kotlin-js plugin to kotlin-jvm plugin for "dokka" task only:

if (!project.gradle.startParameter.taskNames.contains("dokka")) {
    apply plugin: 'kotlin2js'
} else {
    apply plugin: 'kotlin'
}

...

dependencies {
    if (!project.gradle.startParameter.taskNames.contains("dokka")) {
        compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    } else {
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }
}

...

if (!project.gradle.startParameter.taskNames.contains("dokka")) {
    compileKotlin2Js {
        kotlinOptions.metaInfo = true
        kotlinOptions.moduleKind = 'commonjs'
    }
}

This is still not resolved in 0.9.16.

0.9.17 is still having this issue, is there any plans to fix it?

This issue much deeper then just NPE, it caused by Dokka not supporting JS platform right now, it will be fixed as support for JS will be available

Any roadmap for JS support?

It will be added as part of multiplatform projects support

merged to branch. Will be released in 0.9.19.

Was this page helpful?
0 / 5 - 0 ratings