diff --git a/.github/workflows/gradle-test.pr.yml b/.github/workflows/gradle-test.pr.yml index 627304b8ed..743182bb7e 100644 --- a/.github/workflows/gradle-test.pr.yml +++ b/.github/workflows/gradle-test.pr.yml @@ -10,23 +10,25 @@ jobs: test-ubuntu: strategy: matrix: - version: [ 8, 11, 17 ] + javaVersion: [ 8, 11, 17 ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: ${{ matrix.version }} + java-version: ${{ matrix.javaVersion }} cache: 'maven' - uses: gradle/gradle-build-action@v2 + env: + ORG_GRADLE_PROJECT_org.jetbrains.dokka.javaToolchain.test: ${{ matrix.javaVersion }} with: arguments: clean test --stacktrace test-windows: strategy: matrix: - version: [ 11, 17 ] + javaVersion: [ 11, 17 ] fail-fast: false runs-on: windows-latest steps: @@ -34,8 +36,10 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: ${{ matrix.version }} + java-version: ${{ matrix.javaVersion }} cache: 'maven' - uses: gradle/gradle-build-action@v2 + env: + ORG_GRADLE_PROJECT_org.jetbrains.dokka.javaToolchain.test: ${{ matrix.javaVersion }} with: arguments: clean test --stacktrace --no-daemon --parallel --max-workers=1 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 0000000000..57e20acdd8 --- /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 = + 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 = + 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 = + dokkaProperty("kotlinLanguageLevel", KotlinVersion::fromVersion) + + + private fun 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 2073f9a207..befec76fa9 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().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 c4352d1664..a1f6e28840 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 c40ce57c04..c07fc0921b 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().configureEach { compilerOptions { freeCompilerArgs.addAll( @@ -26,7 +23,7 @@ tasks.withType().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 0000000000..78bbc56898 --- /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) diff --git a/gradle.properties b/gradle.properties index d68155d7d9..9b44fe2d67 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,8 @@ # Project Settings dokka_version=1.8.20-SNAPSHOT +org.jetbrains.dokka.javaToolchain.mainCompiler=8 +org.jetbrains.dokka.javaToolchain.testLauncher=8 +org.jetbrains.dokka.kotlinLanguageLevel=1.4 dokka_integration_test_parallelism=2 # Versions kotlin_version=1.8.10 @@ -8,7 +11,6 @@ kotlinx_html_version=0.7.5 kotlin_plugin_version=213-1.8.10-release-430-IJ6777.52 jsoup_version=1.15.3 idea_version=213.6777.52 -language_version=1.4 # jackson 2.13.X does not support kotlin language version 1.4, check before updating jackson_version=2.12.7 # fixes CVE-2022-42003 diff --git a/integration-tests/gradle/build.gradle.kts b/integration-tests/gradle/build.gradle.kts index f47ef6709e..ffc025deef 100644 --- a/integration-tests/gradle/build.gradle.kts +++ b/integration-tests/gradle/build.gradle.kts @@ -22,6 +22,8 @@ tasks.integrationTest { javaLauncher.set(javaToolchains.launcherFor { // kotlinx.coroutines requires Java 11+ - languageVersion.set(JavaLanguageVersion.of(11)) + languageVersion.set(dokkaBuild.testJavaLauncherVersion.map { + maxOf(it, JavaLanguageVersion.of(11)) + }) }) }