diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /build-logic/src/main/kotlin/dokkabuild | |
parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
download | dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2 dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip |
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing
* Update Gradle to 8.4
* Refactor and simplify convention plugins and build scripts
Fixes #3132
---------
Co-authored-by: Adam <897017+aSemy@users.noreply.github.com>
Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'build-logic/src/main/kotlin/dokkabuild')
3 files changed, 126 insertions, 0 deletions
diff --git a/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt new file mode 100644 index 00000000..ad39177c --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package dokkabuild + +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import javax.inject.Inject + +/** + * Common build properties used to build Dokka subprojects. + * + * This is an extension created by the [org.jetbrains.conventions.Base_gradle] convention plugin. + * + * Default values are set in the root `gradle.properties`, and can be overridden via + * [project properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties) + */ +abstract class DokkaBuildProperties @Inject constructor( + private val providers: ProviderFactory, +) { + + /** + * The main version of Java that should be used to build Dokka source code. + * + * Updating the Java target is a breaking change. + */ + val mainJavaVersion: Provider<JavaLanguageVersion> = + dokkaProperty("javaToolchain.mainCompiler", JavaLanguageVersion::of) + + /** + * The version of Java that should be used to run Dokka tests. + * + * This value is set in CI/CD environments to make sure that Dokka still works with different + * versions of Java. + */ + val testJavaLauncherVersion: Provider<JavaLanguageVersion> = + dokkaProperty("javaToolchain.testLauncher", JavaLanguageVersion::of) + .orElse(mainJavaVersion) + + /** + * The Kotlin language level that Dokka artifacts are compiled to support. + * + * Updating the language level is a breaking change. + */ + val kotlinLanguageLevel: Provider<KotlinVersion> = + dokkaProperty("kotlinLanguageLevel", KotlinVersion::fromVersion) + + + private fun <T : Any> dokkaProperty(name: String, convert: (String) -> T) = + providers.gradleProperty("org.jetbrains.dokka.$name").map(convert) + + companion object { + const val EXTENSION_NAME = "dokkaBuild" + } +} diff --git a/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt b/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt new file mode 100644 index 00000000..dd83cf5f --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package dokkabuild + +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType + +object PublicationName { + const val JVM = "jvm" + const val GRADLE_PLUGIN = "pluginMaven" +} + +fun Project.overridePublicationArtifactId( + artifactId: String, + publicationName: String = PublicationName.JVM +) { + extensions.configure<PublishingExtension> { + publications.withType<MavenPublication>().named(publicationName) { + this.artifactId = artifactId + } + } +} diff --git a/build-logic/src/main/kotlin/dokkabuild/internal/GradleKotlinDslAccessors.kt b/build-logic/src/main/kotlin/dokkabuild/internal/GradleKotlinDslAccessors.kt new file mode 100644 index 00000000..7b854f16 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild/internal/GradleKotlinDslAccessors.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +@file:Suppress("PackageDirectoryMismatch") + +package org.gradle.kotlin.dsl // for convenience use a default package for gradle.kts scripts + +import org.gradle.api.Project +import org.gradle.accessors.dm.LibrariesForLibs +import dokkabuild.DokkaBuildProperties + +/* + * Utility functions for accessing Gradle extensions that are created by convention plugins. + * + * (Gradle can't generate the nice DSL accessors for the project that defines them) + * + * These functions are not needed outside the convention plugins project and should be marked as + * `internal` + */ + + +/** + * workaround for accessing version-catalog in convention plugins + * + * See https://github.com/gradle/gradle/issues/15383#issuecomment-779893192 + */ +internal val Project.libs : LibrariesForLibs + get() = extensions.getByType() + +/** + * Retrieves the [dokkaBuild][org.jetbrains.DokkaBuildProperties] extension. + */ +internal val Project.dokkaBuild: DokkaBuildProperties + get() = extensions.getByType() + +/** + * Configures the [dokkaBuild][org.jetbrains.DokkaBuildProperties] extension. + */ +internal fun Project.dokkaBuild(configure: DokkaBuildProperties.() -> Unit) = + extensions.configure(configure) |