Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build config: Gradle Version Catalog + type-safe project dependencies #2884

Merged
merged 13 commits into from Mar 17, 2023
Merged
22 changes: 3 additions & 19 deletions build-logic/build.gradle.kts
@@ -1,5 +1,3 @@
import java.util.*

plugins {
`kotlin-dsl`
}
Expand All @@ -10,22 +8,8 @@ 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("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")
implementation(libs.gradlePlugin.dokka)
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.shadow)
}
6 changes: 6 additions & 0 deletions build-logic/settings.gradle.kts
Expand Up @@ -14,4 +14,10 @@ dependencyResolutionManagement {
google()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
16 changes: 8 additions & 8 deletions build-logic/src/main/kotlin/org/jetbrains/publication.kt
Expand Up @@ -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.*
Expand All @@ -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) {
Expand Down Expand Up @@ -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) }
}
aSemy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
12 changes: 7 additions & 5 deletions 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
Expand Down
18 changes: 7 additions & 11 deletions core/build.gradle.kts
Expand Up @@ -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"))
}

Expand Down
6 changes: 3 additions & 3 deletions core/content-matcher-test-utils/build.gradle.kts
Expand Up @@ -3,8 +3,8 @@ plugins {
}

dependencies {
implementation(project(":core:test-api"))
implementation(kotlin("stdlib-jdk8"))
aSemy marked this conversation as resolved.
Show resolved Hide resolved
implementation(projects.core.testApi)

implementation(kotlin("reflect"))
implementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
implementation(libs.assertk)
}
5 changes: 2 additions & 3 deletions core/test-api/build.gradle.kts
Expand Up @@ -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"))
}

Expand Down
Expand Up @@ -31,6 +31,5 @@ tasks.dokkaHtml {
}

dependencies {
implementation(kotlin("stdlib"))
aSemy marked this conversation as resolved.
Show resolved Hide resolved
testImplementation(kotlin("test-junit"))
}
1 change: 0 additions & 1 deletion examples/gradle/dokka-gradle-example/build.gradle.kts
Expand Up @@ -11,7 +11,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
}

Expand Down
Expand Up @@ -8,7 +8,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))

// Will apply the plugin to all Dokka tasks
Expand Down
Expand Up @@ -10,7 +10,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
}

Expand Down
Expand Up @@ -26,8 +26,3 @@ subprojects {
tasks.dokkaHtmlMultiModule {
moduleName.set("Dokka MultiModule Example")
}

dependencies {
implementation(kotlin("stdlib"))
}

Expand Up @@ -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 {
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -12,10 +12,6 @@ buildscript {
}
}

dependencies {
implementation(kotlin("stdlib"))
}

val currentVersion = "1.0"
val previousVersionsDirectory = project.rootProject.projectDir.resolve("previousDocVersions").invariantSeparatorsPath

Expand Down
@@ -1,3 +1,3 @@
dependencies {
implementation(kotlin("stdlib"))
}

}
@@ -1,3 +1,3 @@
dependencies {
implementation(kotlin("stdlib"))

}
2 changes: 1 addition & 1 deletion examples/plugin/hide-internal-api/build.gradle.kts
Expand Up @@ -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")

Expand Down
113 changes: 113 additions & 0 deletions gradle/libs.versions.toml
@@ -0,0 +1,113 @@
[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"
jsoup = "1.15.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can inline these once-use versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to define all the versions at the top, because it's consistent, it's easier to scan the top to see the versions, and if any versions do need to be re-used then then it's less work (personally I find editing libs.versions.toml a bit fiddly, so I try to avoid it).

Copy link
Contributor

@Goooler Goooler Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can easy to know which versions are reused after inlining unnecessary ones, but either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be consistent - either all versions are at the top, or all of the versions are inlined, otherwise it might eventually lead to chaos. At the moment, I personally don't have any preference, so I'm fine with either approach 👍

idea = "213.6777.52"

jackson = "2.12.7" # jackson 2.13.X does not support kotlin language version 1.4, check before updating
jacksonDatabind = "2.12.7.1" # fixes CVE-2022-42003

freemarker = "2.3.31"

jetbrainsMarkdown = "0.3.1"

soywiz-korte = "2.7.0"

apache-maven = "3.5.0"
apache-mavenArtifact = "3.8.5"
apache-mavenArchiver = "2.5"
apache-mavenPluginTools = "3.5.2"

eclipse-jgit = "5.12.0.202106070339-r"

## test dependency versions ##
junit = "5.9.2"
assertk = "0.25"

## Gradle plugins ##
gradlePlugin-shadow = "7.1.2"
gradlePlugin-binaryCompatibilityValidator = "0.12.1"
gradlePlugin-nexusPublish = "1.1.0"
gradlePlugin-dokka = "1.7.10"
gradlePlugin-gradlePluginPublish = "0.20.0"
gradlePlugin-gradle = "4.0.1"

## NPM ##
node = "16.13.0"


[libraries]

eclipse-jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "eclipse-jgit" }
freemarker = { module = "org.freemarker:freemarker", version.ref = "freemarker" }
jetbrainsIntelliJ-core = { module = "com.jetbrains.intellij.idea:intellij-core", version.ref = "idea" }
jetbrainsIntelliJ-jpsStandalone = { module = "com.jetbrains.intellij.idea:jps-standalone", version.ref = "idea" }
jetbrainsMarkdown = { module = "org.jetbrains:markdown", version.ref = "jetbrainsMarkdown" }
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
soywiz-korte = { module = "com.soywiz.korlibs.korte:korte", version.ref = "soywiz-korte" }
aSemy marked this conversation as resolved.
Show resolved Hide resolved

## Kotlin libs ##
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }

kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
kotlin-idea = { module = "org.jetbrains.kotlin:idea", version.ref = "kotlin" }
kotlin-common = { module = "org.jetbrains.kotlin:common", version.ref = "kotlin" }
kotlin-core = { module = "org.jetbrains.kotlin:core", version.ref = "kotlin" }
kotlin-native = { module = "org.jetbrains.kotlin:native", version.ref = "kotlin" }

kotlinx-cli = { module = "org.jetbrains.kotlinx:kotlinx-cli", version = "0.3.4" }
kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html", version.ref = "kotlinx-html" }
aSemy marked this conversation as resolved.
Show resolved Hide resolved

kotlinx-coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }

## Kotlin Plugins ##
kotlinPlugin-common = { module = "org.jetbrains.kotlin:common", version.ref = "kotlin.plugin" }
kotlinPlugin-idea = { module = "org.jetbrains.kotlin:idea", version.ref = "kotlin.plugin" }
kotlinPlugin-core = { module = "org.jetbrains.kotlin:core", version.ref = "kotlin.plugin" }
kotlinPlugin-native = { module = "org.jetbrains.kotlin:native", version.ref = "kotlin.plugin" }

## Jackson ##
jackson-bom = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
jackson-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jacksonDatabind" }

## Apache Maven ##
apache-mavenArchiver = { module = "org.apache.maven:maven-archiver", version.ref = "apache-mavenArchiver" }
apache-mavenCore = { module = "org.apache.maven:maven-core", version.ref = "apache-maven" }
apache-mavenPluginAnnotations = { module = "org.apache.maven.plugin-tools:maven-plugin-annotations", version.ref = "apache-mavenPluginTools" }
apache-mavenPluginApi = { module = "org.apache.maven:maven-plugin-api", version.ref = "apache-maven" }
apache-mavenArtifact = { module = "org.apache.maven:maven-artifact", version.ref = "apache-mavenArtifact" }


#### test dependencies ####

assertk = { module = "com.willowtreeapps.assertk:assertk", version.ref = "assertk" }

## junit ##
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }


#### Gradle plugins dependencies ####
# The Maven coordinates of Gradle plugins that are either used in convention plugins, or in Dokka subprojects

gradlePlugin-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "gradlePlugin-dokka" }
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
gradlePlugin-shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "gradlePlugin-shadow" }
gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "gradlePlugin-gradle" }


[plugins]
# Gradle Plugins that are applied directly to subprojects
# (Before defining plugins here, first consider creating convention plugins instead,
# and define the Maven coordinates above to be used in build-logic/build.gradle.kts)

kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradlePlugin-binaryCompatibilityValidator" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "gradlePlugin-shadow" }
gradle-pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "gradlePlugin-gradlePluginPublish" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "gradlePlugin-nexusPublish" }
11 changes: 4 additions & 7 deletions integration-tests/build.gradle.kts
Expand Up @@ -3,11 +3,8 @@ plugins {
}

dependencies {
implementation(kotlin("stdlib"))
api(project(":test-utils"))
val coroutines_version: String by project
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
val jsoup_version: String by project
implementation("org.jsoup:jsoup:$jsoup_version")
implementation("org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r")
api(projects.testUtils)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.jsoup)
implementation(libs.eclipse.jgit)
}