diff options
| author | aSemy <897017+aSemy@users.noreply.github.com> | 2023-03-17 15:27:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-17 15:27:03 +0100 |
| commit | 8bb4f4a86b131e9740a8074cb5775930f8280019 (patch) | |
| tree | 2fea9f93d621d1a2c72129358a45a565cca68e6c | |
| parent | 2a3917b7eb70b39360893b61f5cd7f580c41cfda (diff) | |
| download | dokka-8bb4f4a86b131e9740a8074cb5775930f8280019.tar.gz dokka-8bb4f4a86b131e9740a8074cb5775930f8280019.tar.bz2 dokka-8bb4f4a86b131e9740a8074cb5775930f8280019.zip | |
Introduce Gradle Version Catalog with type-safe project dependencies (#2884)
56 files changed, 454 insertions, 436 deletions
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 0c054c5c..5272534d 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -1,5 +1,3 @@ -import java.util.* - plugins { `kotlin-dsl` } @@ -10,22 +8,12 @@ kotlin { } } -// TODO define versions in Gradle Version Catalog https://github.com/Kotlin/dokka/pull/2884 -val properties = file("../gradle.properties").inputStream().use { - Properties().apply { load(it) } -} - -val kotlinVersion = properties["kotlin_version"] - dependencies { - // Import Gradle Plugins that will be used in the buildSrc pre-compiled script plugins, and any `build.gradle.kts` - // files in the project. - // Use their Maven coordinates (plus versions), not Gradle plugin IDs! - // This should be the only place that Gradle plugin versions are defined, so they are aligned across all build scripts + implementation(libs.gradlePlugin.dokka) + implementation(libs.gradlePlugin.kotlin) + implementation(libs.gradlePlugin.shadow) - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2") - implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.12.1") - implementation("io.github.gradle-nexus:publish-plugin:1.1.0") - implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.8.10") + // workaround for accessing version-catalog in convention plugins + // https://github.com/gradle/gradle/issues/15383#issuecomment-779893192 + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) } diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index 55dfe5c1..ed31885b 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -14,4 +14,10 @@ dependencyResolutionManagement { google() gradlePluginPortal() } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } } diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts index ec59da7b..4beeab21 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts +++ b/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts @@ -15,7 +15,7 @@ plugins { base } -abstract class SetupMavenProperties { +abstract class MavenCliSetupExtension { abstract val mavenVersion: Property<String> abstract val mavenPluginToolsVersion: Property<String> abstract val mavenBuildDir: DirectoryProperty @@ -34,10 +34,10 @@ abstract class SetupMavenProperties { abstract val mvn: RegularFileProperty } -val setupMavenProperties = - extensions.create("setupMavenProperties", SetupMavenProperties::class).apply { - mavenVersion.convention(providers.gradleProperty("mavenVersion")) - mavenPluginToolsVersion.convention(providers.gradleProperty("mavenPluginToolsVersion")) +val mavenCliSetupExtension = + extensions.create("mavenCliSetup", MavenCliSetupExtension::class).apply { + mavenVersion.convention(libs.versions.apache.maven) + mavenPluginToolsVersion.convention(libs.versions.apache.mavenPluginTools) mavenBuildDir.convention(layout.buildDirectory.dir("maven")) mavenInstallDir.convention(layout.buildDirectory.dir("apache-maven")) @@ -64,7 +64,7 @@ val mavenBinary by configurations.registering { isVisible = false defaultDependencies { - addLater(setupMavenProperties.mavenVersion.map { mavenVersion -> + addLater(mavenCliSetupExtension.mavenVersion.map { mavenVersion -> project.dependencies.create( group = "org.apache.maven", name = "apache-maven", @@ -77,8 +77,8 @@ val mavenBinary by configurations.registering { } tasks.clean { - delete(setupMavenProperties.mavenBuildDir) - delete(setupMavenProperties.mavenInstallDir) + delete(mavenCliSetupExtension.mavenBuildDir) + delete(mavenCliSetupExtension.mavenInstallDir) } val installMavenBinary by tasks.registering(Sync::class) { @@ -99,5 +99,5 @@ val installMavenBinary by tasks.registering(Sync::class) { } includeEmptyDirs = false } - into(setupMavenProperties.mavenInstallDir) + into(mavenCliSetupExtension.mavenInstallDir) } diff --git a/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt b/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt index 78bbc568..cb8d0df8 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt +++ b/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt @@ -3,6 +3,7 @@ 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 org.jetbrains.DokkaBuildProperties /* @@ -14,6 +15,15 @@ import org.jetbrains.DokkaBuildProperties * `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. */ diff --git a/build-logic/src/main/kotlin/org/jetbrains/publication.kt b/build-logic/src/main/kotlin/org/jetbrains/publication.kt index 60d91c33..32e34dca 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/publication.kt +++ b/build-logic/src/main/kotlin/org/jetbrains/publication.kt @@ -2,13 +2,9 @@ package org.jetbrains import com.github.jengelman.gradle.plugins.shadow.ShadowExtension import org.gradle.api.Project -import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.tasks.PublishToMavenRepository -import org.gradle.api.tasks.TaskContainer -import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import org.gradle.plugins.signing.SigningExtension import org.jetbrains.DokkaPublicationChannel.* @@ -24,7 +20,10 @@ class DokkaPublicationBuilder { } -fun Project.registerDokkaArtifactPublication(publicationName: String, configure: DokkaPublicationBuilder.() -> Unit) { +fun Project.registerDokkaArtifactPublication( + publicationName: String, + configure: DokkaPublicationBuilder.() -> Unit +) { configure<PublishingExtension> { publications { register<MavenPublication>(publicationName) { @@ -143,9 +142,10 @@ private fun Project.signPublicationsIfKeyPresent(vararg publications: String) { useInMemoryPgpKeys(signingKey, signingKeyPassphrase) } publications.forEach { publicationName -> - extensions.findByType(PublishingExtension::class)!!.publications.findByName(publicationName)?.let { - sign(it) - } + extensions.getByType<PublishingExtension>() + .publications + .findByName(publicationName) + ?.let { sign(it) } } } } diff --git a/build.gradle.kts b/build.gradle.kts index 76067b75..5e46c365 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,14 @@ import org.jetbrains.ValidatePublications import org.jetbrains.publicationChannels +@Suppress("DSL_SCOPE_VIOLATION") // fixed in Gradle 8.1 https://github.com/gradle/gradle/pull/23639 plugins { - id("org.jetbrains.conventions.base") apply false - id("org.jetbrains.dokka") version "1.8.10" - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" - id("com.gradle.plugin-publish") version "0.20.0" - id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.1" + id("org.jetbrains.conventions.base") + id("org.jetbrains.conventions.dokka") + + alias(libs.plugins.kotlinx.binaryCompatibilityValidator) + alias(libs.plugins.gradle.pluginPublish) + alias(libs.plugins.nexusPublish) } val dokka_version: String by project diff --git a/core/build.gradle.kts b/core/build.gradle.kts index a59bb0a5..a51e3a62 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -7,26 +7,22 @@ plugins { } dependencies { - api("org.jetbrains:markdown:0.3.1") + api(libs.jetbrainsMarkdown) implementation(kotlin("reflect")) - val jsoup_version: String by project - implementation("org.jsoup:jsoup:$jsoup_version") + implementation(libs.jsoup) - val jackson_version: String by project - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version") - implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version") - val jackson_databind_version: String by project + implementation(libs.jackson.kotlin) + implementation(libs.jackson.xml) constraints { - implementation("com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version") { + implementation(libs.jackson.databind) { because("CVE-2022-42003") } } - val coroutines_version: String by project - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") + implementation(libs.kotlinx.coroutines.core) - testImplementation(project(":core:test-api")) + testImplementation(projects.core.testApi) testImplementation(kotlin("test-junit")) } diff --git a/core/content-matcher-test-utils/build.gradle.kts b/core/content-matcher-test-utils/build.gradle.kts index 4ddba0fb..75602c64 100644 --- a/core/content-matcher-test-utils/build.gradle.kts +++ b/core/content-matcher-test-utils/build.gradle.kts @@ -3,8 +3,8 @@ plugins { } dependencies { - implementation(project(":core:test-api")) - implementation(kotlin("stdlib-jdk8")) + implementation(projects.core.testApi) + implementation(kotlin("reflect")) - implementation("com.willowtreeapps.assertk:assertk-jvm:0.25") + implementation(libs.assertk) } diff --git a/core/test-api/build.gradle.kts b/core/test-api/build.gradle.kts index b9137009..1eb8f00c 100644 --- a/core/test-api/build.gradle.kts +++ b/core/test-api/build.gradle.kts @@ -6,10 +6,9 @@ plugins { } dependencies { - api(project(":core")) - implementation(project(":kotlin-analysis")) + api(projects.core) + implementation(projects.kotlinAnalysis) implementation("junit:junit:4.13.2") // TODO: remove dependency to junit - implementation(kotlin("stdlib")) implementation(kotlin("reflect")) } diff --git a/examples/gradle/dokka-customFormat-example/build.gradle.kts b/examples/gradle/dokka-customFormat-example/build.gradle.kts index da22dda5..594d65d3 100644 --- a/examples/gradle/dokka-customFormat-example/build.gradle.kts +++ b/examples/gradle/dokka-customFormat-example/build.gradle.kts @@ -31,6 +31,5 @@ tasks.dokkaHtml { } dependencies { - implementation(kotlin("stdlib")) testImplementation(kotlin("test-junit")) } diff --git a/examples/gradle/dokka-gradle-example/build.gradle.kts b/examples/gradle/dokka-gradle-example/build.gradle.kts index dc38461c..30cb4d72 100644 --- a/examples/gradle/dokka-gradle-example/build.gradle.kts +++ b/examples/gradle/dokka-gradle-example/build.gradle.kts @@ -11,7 +11,6 @@ repositories { } dependencies { - implementation(kotlin("stdlib")) testImplementation(kotlin("test-junit")) } diff --git a/examples/gradle/dokka-kotlinAsJava-example/build.gradle.kts b/examples/gradle/dokka-kotlinAsJava-example/build.gradle.kts index 96a47451..d1335e47 100644 --- a/examples/gradle/dokka-kotlinAsJava-example/build.gradle.kts +++ b/examples/gradle/dokka-kotlinAsJava-example/build.gradle.kts @@ -8,7 +8,6 @@ repositories { } dependencies { - implementation(kotlin("stdlib")) testImplementation(kotlin("test-junit")) // Will apply the plugin to all Dokka tasks diff --git a/examples/gradle/dokka-library-publishing-example/build.gradle.kts b/examples/gradle/dokka-library-publishing-example/build.gradle.kts index 3349702e..b01322ee 100644 --- a/examples/gradle/dokka-library-publishing-example/build.gradle.kts +++ b/examples/gradle/dokka-library-publishing-example/build.gradle.kts @@ -10,7 +10,6 @@ repositories { } dependencies { - implementation(kotlin("stdlib")) testImplementation(kotlin("test-junit")) } diff --git a/examples/gradle/dokka-multimodule-example/parentProject/build.gradle.kts b/examples/gradle/dokka-multimodule-example/parentProject/build.gradle.kts index 66b32b18..da7b382e 100644 --- a/examples/gradle/dokka-multimodule-example/parentProject/build.gradle.kts +++ b/examples/gradle/dokka-multimodule-example/parentProject/build.gradle.kts @@ -26,8 +26,3 @@ subprojects { tasks.dokkaHtmlMultiModule { moduleName.set("Dokka MultiModule Example") } - -dependencies { - implementation(kotlin("stdlib")) -} - diff --git a/examples/gradle/dokka-multimodule-example/parentProject/childProjectA/build.gradle.kts b/examples/gradle/dokka-multimodule-example/parentProject/childProjectA/build.gradle.kts index e13819a1..7b3b1e23 100644 --- a/examples/gradle/dokka-multimodule-example/parentProject/childProjectA/build.gradle.kts +++ b/examples/gradle/dokka-multimodule-example/parentProject/childProjectA/build.gradle.kts @@ -5,10 +5,6 @@ plugins { id("org.jetbrains.dokka") } -dependencies { - implementation(kotlin("stdlib")) -} - // configuration specific to this subproject. // notice the use of Partial task tasks.withType<DokkaTaskPartial>().configureEach { diff --git a/examples/gradle/dokka-multimodule-example/parentProject/childProjectB/build.gradle.kts b/examples/gradle/dokka-multimodule-example/parentProject/childProjectB/build.gradle.kts index 089813a8..e8b40d4a 100644 --- a/examples/gradle/dokka-multimodule-example/parentProject/childProjectB/build.gradle.kts +++ b/examples/gradle/dokka-multimodule-example/parentProject/childProjectB/build.gradle.kts @@ -5,10 +5,6 @@ plugins { id("org.jetbrains.dokka") } -dependencies { - implementation(kotlin("stdlib")) -} - // configuration specific to this subproject. // notice the use of Partial task tasks.withType<DokkaTaskPartial>().configureEach { diff --git a/examples/gradle/dokka-versioning-multimodule-example/parentProject/build.gradle.kts b/examples/gradle/dokka-versioning-multimodule-example/parentProject/build.gradle.kts index 295b4485..59d0181f 100644 --- a/examples/gradle/dokka-versioning-multimodule-example/parentProject/build.gradle.kts +++ b/examples/gradle/dokka-versioning-multimodule-example/parentProject/build.gradle.kts @@ -12,10 +12,6 @@ buildscript { } } -dependencies { - implementation(kotlin("stdlib")) -} - val currentVersion = "1.0" val previousVersionsDirectory = project.rootProject.projectDir.resolve("previousDocVersions").invariantSeparatorsPath diff --git a/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectA/build.gradle.kts b/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectA/build.gradle.kts index dd9f5199..bf1513f8 100644 --- a/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectA/build.gradle.kts +++ b/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectA/build.gradle.kts @@ -1,3 +1 @@ -dependencies { - implementation(kotlin("stdlib")) -}
\ No newline at end of file +// intentionally empty - build config is set in the root build.gradle.kts diff --git a/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectB/build.gradle.kts b/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectB/build.gradle.kts index fceff829..bf1513f8 100644 --- a/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectB/build.gradle.kts +++ b/examples/gradle/dokka-versioning-multimodule-example/parentProject/childProjectB/build.gradle.kts @@ -1,3 +1 @@ -dependencies { - implementation(kotlin("stdlib")) -} +// intentionally empty - build config is set in the root build.gradle.kts diff --git a/examples/plugin/hide-internal-api/build.gradle.kts b/examples/plugin/hide-internal-api/build.gradle.kts index ed8169ad..533bbd60 100644 --- a/examples/plugin/hide-internal-api/build.gradle.kts +++ b/examples/plugin/hide-internal-api/build.gradle.kts @@ -19,7 +19,7 @@ repositories { val dokkaVersion: String by project dependencies { - implementation(kotlin("stdlib")) + compileOnly("org.jetbrains.dokka:dokka-core:$dokkaVersion") implementation("org.jetbrains.dokka:dokka-base:$dokkaVersion") diff --git a/gradle.properties b/gradle.properties index 9b44fe2d..2fe431fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,21 +4,7 @@ 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 -coroutines_version=1.6.3 -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 -# jackson 2.13.X does not support kotlin language version 1.4, check before updating -jackson_version=2.12.7 -# fixes CVE-2022-42003 -jackson_databind_version=2.12.7.1 -freemarker_version=2.3.31 -# Dokka Maven Plugin versions -mavenVersion=3.5.0 -mavenPluginToolsVersion=3.5.2 + # Code style kotlin.code.style=official # Gradle settings diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..0587660f --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,115 @@ +[versions] + +kotlin = "1.8.10" +kotlin-plugin = "213-1.8.10-release-430-IJ6777.52" +kotlinx-coroutines = "1.6.3" +kotlinx-html = "0.7.5" +kotlinx-cli = "0.3.4" + +idea = "213.6777.52" +jetbrainsMarkdown = "0.3.1" + +jsoup = "1.15.3" + + |
