diff options
Diffstat (limited to 'build-logic')
5 files changed, 118 insertions, 7 deletions
diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaBuildProperties.kt b/build-logic/src/main/kotlin/org/jetbrains/DokkaBuildProperties.kt new file mode 100644 index 00000000..57e20acd --- /dev/null +++ b/build-logic/src/main/kotlin/org/jetbrains/DokkaBuildProperties.kt @@ -0,0 +1,54 @@ +package org.jetbrains + +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 + * [CLI args, system properties, and environment variables](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/org/jetbrains/conventions/base-java.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/base-java.gradle.kts index 2073f9a2..befec76f 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/base-java.gradle.kts +++ b/build-logic/src/main/kotlin/org/jetbrains/conventions/base-java.gradle.kts @@ -8,15 +8,39 @@ package org.jetbrains.conventions */ plugins { + id("org.jetbrains.conventions.base") java } java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(dokkaBuild.mainJavaVersion) } } java { withSourcesJar() } + +tasks.withType<Test>().configureEach { + useJUnitPlatform() + + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(dokkaBuild.testJavaLauncherVersion) + }) +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.2")) + // TODO Upgrade all subprojects to use JUnit Jupiter https://github.com/Kotlin/dokka/issues/2924 + // Replace these dependencies with `testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")` + // See https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle-engines-configure + // Ideally convention plugins should only provide sensible defaults that can be overridden by subprojects. + // If a convention plugin defines dependencies, these cannot be easily overridden by subprojects, and so + // this should be avoided. However, for now , both JUnit 4 and 5 must be supported, and since these are test + // runtime-only dependencies they are not going to have a significant impact subprojects. + // These dependencies should be revisited in #2924, and (for example) moved to each subproject (which is more + // repetitive, but more declarative and clear), or some other solution. + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") + testRuntimeOnly("org.junit.vintage:junit-vintage-engine") +} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts index c4352d16..a1f6e288 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts +++ b/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts @@ -1,10 +1,19 @@ package org.jetbrains.conventions +import org.jetbrains.DokkaBuildProperties + +/** + * A convention plugin that sets up common config and sensible defaults for all subprojects. + * + * It provides the [DokkaBuildProperties] extension, for accessing common build properties. + */ + plugins { base } -// common Gradle configuration that should be applied to all projects +val dokkaBuildProperties: DokkaBuildProperties = extensions.create(DokkaBuildProperties.EXTENSION_NAME) + if (project != rootProject) { project.group = rootProject.group diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts index c40ce57c..c07fc092 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts +++ b/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts @@ -1,7 +1,6 @@ package org.jetbrains.conventions import org.jetbrains.configureDokkaVersion -import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -12,8 +11,6 @@ plugins { configureDokkaVersion() -val language_version: String by project - tasks.withType<KotlinCompile>().configureEach { compilerOptions { freeCompilerArgs.addAll( @@ -26,7 +23,7 @@ tasks.withType<KotlinCompile>().configureEach { ) ) allWarningsAsErrors.set(true) - languageVersion.set(KotlinVersion.fromVersion(language_version)) - apiVersion.set(KotlinVersion.fromVersion(language_version)) + languageVersion.set(dokkaBuild.kotlinLanguageLevel) + apiVersion.set(dokkaBuild.kotlinLanguageLevel) } } diff --git a/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt b/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt new file mode 100644 index 00000000..78bbc568 --- /dev/null +++ b/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt @@ -0,0 +1,27 @@ +@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.jetbrains.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` + */ + +/** + * 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) |