heyall, i’m having trouble getting my docs to link...
# dokka
c
heyall, i’m having trouble getting my docs to link to source code. i’ve been kind of banging my head against the wall. it’s an Android multi-module project. it’s not showing the link to the source code in the dokka output. here’s an example of my code
Copy code
allprojects {
  apply(plugin = "org.jetbrains.dokka")

  tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial>().configureEach {
    dokkaSourceSets.configureEach {
      includes.from("Module.md")

      sourceLink {
        localDirectory.set(projectDir.resolve("src/main/java"))
        val branch = "main"
        val moduleName = project.name
        val srcDir = "src/main/java"
        val rootUrl = "<https://internalgithub.com/app/tree>"
        val url = "$rootUrl/$branch/$moduleName/$srcDir"
        remoteUrl.set(java.net.URL(url))
      }
    }
  }
}
i
Hi! Hm, I don't see what could be wrong right away The only thing that comes to mind is that you have
src/main/java
, maybe try just
src
instead? You can look at the configuration of source links for kotlinx.coroutines, maybe that'll give you an idea
c
i think i tried that, but i’ll try again. i thought it would create the link even if the paths were wrong
at this point i’d be happy with a 404 😅
you mean for the local path or the remote URL?
i
Try both
I believe Dokka takes an individual file and then looks at its declaration path. If the file's path matches the
localDirectory
setting from the source link configuration, it adds the source link button to the signature. So if the button is not showing up at all, the problem might in the local directory You can try debugging it with
println
to see which value is passed in there
💯 1
c
as in
println(localDirectory)
?
i
something like that, yeah. Or
println(projectDir.resolve("src/main/java"))
within the configuration block
c
i’ll do both 💯
so i tried to change it to
localDirectory.set(projectDir.resolve("src"))
, and i’m still not getting the links in the output 😕
Android Studio is picking up the links. both to
src
and
src/main/java
. this is my first experience with Dokka, but my assumption is that it needs the full
src/main/java
in order to append the package name to that? e.g.
<http://dev.covercash.app|dev.covercash.app>
->
src/main/java/dev/coverash/app
i
I can take a look if your project is open source, it must be something very simple If it's closed source - my only advice is to start out with a smaller project (like dokka-gradle-example which already has source links), make sure that the links work overall, and then try to do the same thing in your production project But I think the problem must be in a small detail somewhere 🙂
I've added the configuration of source links to our Gradle multimodule example: https://github.com/Kotlin/dokka/pull/2966/files Seems to work just fine, not sure what the problem is in your case 😞
c
it’s a closed-source company product, unfortunately 😞 i’ve been through the examples, but we have a pretty complex Android app. sometimes it’s hard to reconcile atomic examples with real-world code 😅 i’ll look over that PR and see if that works 💯
so i haven’t fixed this yet, but i did find something: it’s only our Android modules that aren’t linking source docs correctly. it ended up that we do need it to be
localDirectory.set(projectDir.resolve("src/main/java")
, and in our Kotlin-only module the source code is linked properly. however, all our other modules have Android dependencies and do not link correctly. i’m not certain this is the problem, but it seems to be the only difference i can find
i’ve also added
Copy code
noStdlibLink.set(true)
noJdkLink.set(true)
noAndroidSdkLink.set(true)
since i’m having trouble getting those to download in our corporate network
i
Oh, it looks like something broke and it's now a bug 😞 I now remember that there was a report about it already: https://github.com/Kotlin/dokka/issues/2876
💯 1
c
@Ignat Beresnev good to know at least! thanks for your help. i’ll check it out