From 5f3af11de14cdadd20d844caf54942ce0f9312e0 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:12:04 +0100 Subject: [PATCH] update html log link to relativize the path using `user.dir` Hopefully fixes an issue where the link didn't work in composite builds. --- .../src/main/kotlin/formats/DokkatooHtmlPlugin.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/dokkatoo-plugin/src/main/kotlin/formats/DokkatooHtmlPlugin.kt b/modules/dokkatoo-plugin/src/main/kotlin/formats/DokkatooHtmlPlugin.kt index 0ec54eb8..3bbf1035 100644 --- a/modules/dokkatoo-plugin/src/main/kotlin/formats/DokkatooHtmlPlugin.kt +++ b/modules/dokkatoo-plugin/src/main/kotlin/formats/DokkatooHtmlPlugin.kt @@ -77,9 +77,19 @@ constructor( val indexHtmlFile = generatePublicationTask .flatMap { it.outputDirectory.file("index.html") } - val indexHtmlPath = indexHtmlFile.map { indexHtml -> + // assume that user.dir is IntelliJ's current project directory + val userDir = providers.systemProperty("user.dir") + .map(::File) + + val indexHtmlPath = providers.zip(userDir, indexHtmlFile) { baseDir, indexHtml -> + // IntelliJ built-in webserver needs the path to start with the project dir. + // E.g. If the project is in /user/rachel/my-project/ + // the link should start with http://localhost:63342/my-project/ + // So, relativize the path to index.html to include the project dir name. + // (Keep composite builds in mind when changing ths property, as the project rootDir might + // not be the current IJ project dir.) indexHtml.asFile - .relativeTo(project.rootDir.parentFile) + .relativeTo(baseDir.parentFile) .invariantSeparatorsPath }