Skip to content

Commit

Permalink
automatically add version for Dokka dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
aSemy committed Dec 16, 2023
1 parent f9546e6 commit ca4c23c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 28 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ dokkatoo {
suppressObviousFunctions.set(true)
suppressObviousFunctions.set(false)
}
// The default versions that Dokkatoo uses can be overridden:
versions {
jetbrainsDokka.set("1.9.10")
}
}
```

Expand All @@ -156,12 +160,9 @@ dependencies {
dokkatoo(projects(":subproject-hello"))
dokkatoo(projects(":subproject-world"))

// This is required at the moment, see https://github.com/adamko-dev/dokkatoo/issues/14
dokkatooPluginHtml(
dokkatoo.versions.jetbrainsDokka.map { dokkaVersion ->
"org.jetbrains.dokka:all-modules-page-plugin:$dokkaVersion"
}
)
// A dependency on all-modules-page-plugin is required at the moment, see https://github.com/adamko-dev/dokkatoo/issues/14
// A version is not required, Dokkatoo will automatically add one.
dokkatooPluginHtml("org.jetbrains.dokka:all-modules-page-plugin")
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ idea {
addAll(
projectDir.walk().filter { file ->
excludedDirs.any {
file.invariantSeparatorsPath.endsWith(it)
file.invariantSeparatorsPath.endsWith("/$it")
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ plugins {
dependencies {
dokkatoo(project(":parentProject:childProjectA"))
dokkatoo(project(":parentProject:childProjectB"))
dokkatooPluginHtml(
dokkatoo.versions.jetbrainsDokka.map { dokkaVersion ->
"org.jetbrains.dokka:all-modules-page-plugin:$dokkaVersion"
}
)
dokkatooPluginHtml(
dokkatoo.versions.jetbrainsDokka.map { dokkaVersion ->
"org.jetbrains.dokka:templating-plugin:$dokkaVersion"
}
)

dokkatooPluginHtml("org.jetbrains.dokka:all-modules-page-plugin")
dokkatooPluginHtml("org.jetbrains.dokka:templating-plugin")
}

dokkatoo {
Expand Down
4 changes: 4 additions & 0 deletions modules/dokkatoo-plugin/api/dokkatoo-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,17 @@ public final class dev/adamko/dokkatoo/dokka/plugins/PluginConfigValue$Values :
}

public abstract class dev/adamko/dokkatoo/formats/DokkatooFormatPlugin : org/gradle/api/Plugin {
public static final field Companion Ldev/adamko/dokkatoo/formats/DokkatooFormatPlugin$Companion;
public fun <init> (Ljava/lang/String;)V
public synthetic fun apply (Ljava/lang/Object;)V
public fun apply (Lorg/gradle/api/Project;)V
public fun configure (Ldev/adamko/dokkatoo/formats/DokkatooFormatPlugin$DokkatooFormatPluginContext;)V
public final fun getFormatName ()Ljava/lang/String;
}

public final class dev/adamko/dokkatoo/formats/DokkatooFormatPlugin$Companion {
}

public final class dev/adamko/dokkatoo/formats/DokkatooFormatTasks$inlined$sam$i$org_gradle_api_Action$0 : org/gradle/api/Action {
public fun <init> (Lkotlin/jvm/functions/Function1;)V
public final synthetic fun execute (Ljava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DokkatooFormatDependencyContainers(
*
* Users can add plugins to this dependency.
*
* Should not contain runtime dependencies.
* Should not contain runtime dependencies - use [dokkaGeneratorClasspath].
*/
val dokkaPluginsClasspath: NamedDomainObjectProvider<Configuration> =
project.configurations.register(dependencyContainerNames.dokkaPluginsClasspath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -104,6 +105,29 @@ abstract class DokkatooFormatPlugin(
addDefaultDokkaDependencies()
}
}

if (context.enableVersionAlignment) {
//region version alignment
listOf(
dependencyContainers.dokkaPluginsClasspath,
dependencyContainers.dokkaPluginsIntransitiveClasspath,
dependencyContainers.dokkaGeneratorClasspath,
).forEach {
// Add a version if one is missing, which will allow defining a org.jetbrains.dokka
// dependency without a version.
// (It would be nice to do this with a virtual-platform, but Gradle is bugged:
// https://github.com/gradle/gradle/issues/27435)
it.configure {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.dokka" && requested.version.isNullOrBlank()) {
logger.info("adding version of dokka dependency '$requested'")
useVersion(dokkatooExtension.versions.jetbrainsDokka.get())
}
}
}
}
//endregion
}
}
}

Expand All @@ -122,6 +146,7 @@ abstract class DokkatooFormatPlugin(
private val dependencyContainerNames = DokkatooBasePlugin.DependencyContainerNames(formatName)

var addDefaultDokkaDependencies = true
var enableVersionAlignment = true

/** Create a [Dependency] for a Dokka module */
fun DependencyHandler.dokka(module: String): Provider<Dependency> =
Expand Down Expand Up @@ -171,4 +196,7 @@ abstract class DokkatooFormatPlugin(
}
}

companion object {
private val logger = Logging.getLogger(DokkatooFormatPlugin::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,7 @@ private fun initDokkatooProject(
|dependencies {
| dokkatoo(project(":subproject-hello"))
| dokkatoo(project(":subproject-goodbye"))
| dokkatooPluginHtml(
| dokkatoo.versions.jetbrainsDokka.map { dokkaVersion ->
| "org.jetbrains.dokka:all-modules-page-plugin:${'$'}dokkaVersion"
| }
| )
| dokkatooPluginHtml("org.jetbrains.dokka:all-modules-page-plugin")
|}
|
""".trimMargin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ private fun initDokkatooProject(
|}
|
|dependencies {
| dokkatooPluginHtml(
| dokkatoo.versions.jetbrainsDokka.map { dokkaVersion ->
| "org.jetbrains.dokka:all-modules-page-plugin:${'$'}dokkaVersion"
| }
| )
| dokkatooPluginHtml("org.jetbrains.dokka:all-modules-page-plugin")
|}
|
|tasks.withType<dev.adamko.dokkatoo.tasks.LogHtmlPublicationLinkTask>().configureEach {
Expand Down

0 comments on commit ca4c23c

Please sign in to comment.