Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplatform branch cannot extract KotlinCompilation from kotlin-android projects #491

Closed
jhansche opened this issue Jul 26, 2019 · 1 comment
Labels
Milestone

Comments

@jhansche
Copy link

jhansche commented Jul 26, 2019

org.jetbrains.dokka.gradle.ConfigurationExtractor.getMainCompilation(KotlinTarget) only works if there is a target.compilations.getByName("main"). On Android projects, there is no "main" compilation (typically just "debug", "release", and a few others for tests).

The first problem is that getByName(String) throws an exception if the named element cannot be found. Since Android does not create a "main" compilation, this was causing the build to fail. To work around that exception, I first changed this to findByName("main"), and that resolved the exception. However, even after this, the generated documentation was empty, because it was not able to locate any sources or classpath.

I tried adding kotlinTasks { ["compileReleaseKotlin"] }, based on what I found in the testData examples, but that did not change anything and it would still produce empty documentation. I wasn't able to find out how to run the integration tests to check whether it was expected to work or not.

What finally ended up working for me, was one of these changes:

target?.compilations?.findByName("main") ?: target?.compilations?.first()
listOf("main", "release", "debug").mapNotNull {
    target?.compilations?.findByName(it)
}.first()

Now it's able to locate the "release" compilation, finds the sources and classpath, and the documentation is generated successfully.

It might make sense to run this only for release variants, in which case it would be nice if the dokka-android plugin would create the tasks only for release variants, or at least generate separate DokkaAndroidTask for separate variants that will utilize the matching KotlinCompilation. But as I'm not familiar with the roadmap for where you intend to take this, I don't really know the best way to address this in order to create a PR.

@kamildoleglo kamildoleglo added this to the 0.9.19 milestone Aug 12, 2019
@kamildoleglo
Copy link
Contributor

Fixed in da9d43e
Thank you for reporting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants