如何使用maven repository分发javadoc沿着我的jar库工件?

y1aodyip  于 2023-08-03  发布在  Maven
关注(0)|答案(1)|浏览(149)

我有一个KotlinJVM库,我通过maven存储库将其作为.jar工件分发。我想为它提供一些Kdocs,以便它可以通过IntelliJ Idea的快速文档工具(ctrl+q)使用。我用dokka gradle插件生成html文档,用maven-publish插件分发我的工件。
下面是我的build.gradle.kts文件的内容:

  1. import java.util.*
  2. plugins {
  3. kotlin("jvm") version "1.8.0"
  4. id("org.jetbrains.dokka") version "1.8.10"
  5. `maven-publish`
  6. }
  7. group = "com.example"
  8. version = "1.0"
  9. fun RepositoryHandler.repsy(): MavenArtifactRepository{
  10. return maven(repoProperty("url")){
  11. credentials{
  12. username = repoProperty("username")
  13. password = repoProperty("password")
  14. }
  15. }
  16. }
  17. fun repoProperty(name: String): String = Properties().run {
  18. load(file("repo.properties").inputStream())
  19. get(name) as String
  20. }
  21. repositories {
  22. mavenCentral()
  23. }
  24. publishing{
  25. repositories{
  26. repsy()
  27. }
  28. publications{
  29. create("main", MavenPublication::class.java){
  30. artifactId = project.name
  31. version = project.version as String
  32. groupId = project.group as String
  33. artifact(file(".\\build\\libs\\${project.name}-${project.version}.jar"))
  34. artifact(file(".\\build\\dokka\\html\\index.html")){
  35. classifier = "javadoc"
  36. }
  37. }
  38. }
  39. }
  40. dependencies {
  41. testImplementation(kotlin("test"))
  42. implementation("com.google.code.gson:gson:2.10.1")
  43. }
  44. tasks.test {
  45. useJUnitPlatform()
  46. }
  47. kotlin {
  48. jvmToolchain(11)
  49. }

字符串
下面是我的仓库的内容:enter image description here
我的藏物被Gradle解决了没问题。然而,Idea无法解析文档。此外,html文件不能正确导航通过,如果下载单独从存储库。Dokka生成的文件包含了很多其他的内容,但是我找到的所有指南都保证我只需要上传index.html文件。
问题是,我做错了什么,以及如何正确地分发dokka生成的kdocs?

mwg9r5ms

mwg9r5ms1#

你能试试下面的解决方案吗,让我知道它是怎么回事吗?

  1. val javadocJar by tasks.register<Jar>("dokkaHtmlJar") {
  2. group = "documentation"
  3. dependsOn(tasks.dokkaHtml)
  4. from(tasks.dokkaHtml.flatMap { it.outputDirectory })
  5. archiveClassifier.set("javadoc")
  6. }
  7. val sourcesJar by tasks.named("sourcesJar")
  8. publishing{
  9. repositories{
  10. repsy()
  11. }
  12. publications{
  13. create("main", MavenPublication::class.java){
  14. artifactId = project.name
  15. version = project.version as String
  16. groupId = project.group as String
  17. from(components["kotlin"])
  18. artifact(file(".\\build\\libs\\" +
  19. "${project.name}-${project.version}.jar"))
  20. artifact(javadocJar)
  21. artifact(sourcesJar)
  22. }
  23. }
  24. }

字符串
我也提供了sourcesJar的代码,因为如果您希望将库发布到Maven Central,这也是必需的。

展开查看全部

相关问题