Skip to content

Commit

Permalink
build: move all dependencies into version catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodongw committed Jul 16, 2022
1 parent 1a8d642 commit 301e4ef
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 55 deletions.
12 changes: 5 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import build.*
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down Expand Up @@ -36,13 +35,12 @@ allprojects {
}

dependencies {
implementation("io.github.microutils:kotlin-logging:2.1.21")
// "libs" not working, must use "rootProject.libs" here
// https://github.com/gradle/gradle/issues/16634
implementation(rootProject.libs.kotlin.logging)

testImplementation("io.kotest:kotest-framework-engine-jvm:${Deps.kotestVersion}")
testImplementation("io.kotest:kotest-runner-junit5-jvm:${Deps.kotestVersion}")
testImplementation("io.kotest:kotest-assertions-core-jvm:${Deps.kotestVersion}")
testImplementation("ch.qos.logback:logback-classic:1.2.3")
// testImplementation("org.slf4j:slf4j-simple:1.7.25")
testImplementation(rootProject.libs.bundles.kotest)
testImplementation(rootProject.libs.logback.classic)
}

// set target jvm version, otherwise gradle will use the jdk version during compiling for "org.gradle.jvm.version" in module file
Expand Down
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/build/Common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package build

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

fun Project.versionCatalog(name: String): VersionCatalog {
return extensions.getByType<VersionCatalogsExtension>().named(name)
}

fun VersionCatalog.library(name: String) = findLibrary(name).get()
fun VersionCatalog.version(name: String) = findVersion(name).get()
11 changes: 0 additions & 11 deletions buildSrc/src/main/kotlin/build/Deps.kt

This file was deleted.

11 changes: 6 additions & 5 deletions buildSrc/src/main/kotlin/build/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import org.gradle.plugins.signing.SigningExtension
* Config the project as a library.
* It adds Kotlin dependency, and publishing support.
*/
fun Project.librarySupport() {
fun Project.configureLibrary() {
val api by configurations
val implementation by configurations
val dokkaHtmlPlugin by configurations
val libs = versionCatalog("libs")

dependencies {
api(kotlin("stdlib-jdk8"))
api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${Deps.kotlinCoroutineVersion}")
implementation("org.slf4j:slf4j-api:1.7.25")
api(libs.library("kotlin.stdlib"))
api(libs.library("kotlinx.coroutines"))
implementation(libs.library("slf4j.api"))

dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.10")
dokkaHtmlPlugin(libs.library("dokka.kotlin.as.java.plugin"))
}

val sourceSets = extensions.getByName("sourceSets") as SourceSetContainer
Expand Down
7 changes: 4 additions & 3 deletions buildSrc/src/main/kotlin/build/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ private fun goOs(os: String): String {
* Configure the project as a GRPC plugin.
* It adds support for compiling the plugin to Linux, Windows and MacOS, and publishing support.
*/
fun Project.grpcPluginSupport(pluginName: String) {
fun Project.configureGrpcPlugin(pluginName: String) {
val testImplementation by configurations
val libs = versionCatalog("libs")
dependencies {
testImplementation(kotlin("stdlib-jdk8"))
testImplementation(libs.library("kotlin-stdlib"))
}

// overwrite os & arch if specified by command line
Expand Down Expand Up @@ -67,7 +68,7 @@ fun Project.grpcPluginSupport(pluginName: String) {
protobuf {
generatedFilesBaseDir = "$projectDir/gen"
protoc {
artifact = "com.google.protobuf:protoc:${Deps.protobufVersion}"
artifact = "com.google.protobuf:protoc:${libs.version("protobuf")}"
}
plugins {
id("grpc-kert") {
Expand Down
58 changes: 58 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# https://docs.gradle.org/current/userguide/platforms.html#sub:conventional-dependencies-toml

[versions]
kotlin = "1.6.10"
kotlinx-coroutines = "1.6.0"
vertx = "4.2.4"
protobuf = "3.19.4"
grpc = "1.44.0"
kotest = "5.1.0"
jackson = "2.13.1"
graphql-kotlin = "5.3.2"
kotlin-logging = "2.1.21"
logback = "1.2.3"
slf4j = "1.7.30"

[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-script-runtime = { module = "org.jetbrains.kotlin:kotlin-script-runtime", version.ref = "kotlin" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-slf4j = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-slf4j", version.ref = "kotlinx-coroutines" }
vertx-web = { module = "io.vertx:vertx-web", version.ref = "vertx" }
vertx-lang-kotlin-coroutines = { module = "io.vertx:vertx-lang-kotlin-coroutines", version.ref = "vertx" }
vertx-web-client = { module = "io.vertx:vertx-web-client", version.ref = "vertx" }
protobuf-kotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "protobuf" }
protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" }
grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "grpc" }
grpc-netty = { module = "io.grpc:grpc-netty", version.ref = "grpc" }
javax-annotation-api = { module = "javax.annotation:javax.annotation-api", version = "1.3.2" }
protoc-gen-grpc-java = { module = "io.grpc:protoc-gen-grpc-java", version.ref = "grpc" }
protoc = { module = "com.google.protobuf:protoc", version.ref = "protobuf" }
graphql-kotlin-server = { module = "com.expediagroup:graphql-kotlin-server", version.ref = "graphql-kotlin" }
graphql-kotlin-client = { module = "com.expediagroup:graphql-kotlin-client", version.ref = "graphql-kotlin" }
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-module-afterburner = { module = "com.fasterxml.jackson.module:jackson-module-afterburner", version.ref = "jackson" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
dokka-kotlin-as-java-plugin = { module = "org.jetbrains.dokka:kotlin-as-java-plugin", version.ref = "kotlin" }
kotlin-logging = { module = "io.github.microutils:kotlin-logging", version.ref = "kotlin-logging" }
kotest-framework-engine-jvm = { module = "io.kotest:kotest-framework-engine-jvm", version.ref = "kotest" }
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }

[bundles]
kotlin = [
"kotlin-stdlib",
"kotlin-reflect",
"kotlin-script-runtime"
]
kotest = [
"kotest-framework-engine-jvm",
"kotest-runner-junit5",
"kotest-assertions-core"
]

[plugins]
15 changes: 6 additions & 9 deletions kert-graphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ plugins {

description = "Kert GraphQL support"

librarySupport()
configureLibrary()

dependencies {
val graphqlKotlinVersion = "5.3.2"
val jacksonVersion = "2.13.1"

api(project(":kert-http"))
api("com.expediagroup:graphql-kotlin-server:${graphqlKotlinVersion}")
api("com.expediagroup:graphql-kotlin-client:${graphqlKotlinVersion}")
api(libs.graphql.kotlin.server)
api(libs.graphql.kotlin.client)

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${jacksonVersion}")
implementation("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
implementation(libs.jackson.databind)
implementation(libs.jackson.module.kotlin)
implementation(libs.jackson.module.afterburner)
}

//graphql {
Expand Down
4 changes: 2 additions & 2 deletions kert-grpc-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import build.*

description = "The protoc plugin for Kert"

grpcPluginSupport("protoc-gen-grpc-kert")
configureGrpcPlugin("protoc-gen-grpc-kert")

dependencies {
testImplementation(project(":kert-grpc"))
testImplementation("com.google.protobuf:protobuf-kotlin:${Deps.protobufVersion}")
testImplementation(libs.protobuf.kotlin)
}

tasks {
Expand Down
18 changes: 9 additions & 9 deletions kert-grpc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import com.google.protobuf.gradle.*

description = "Kert GRPC support"

librarySupport()
configureLibrary()

dependencies {
api(project(":kert-http"))
api("com.google.protobuf:protobuf-java:${Deps.protobufVersion}")
api("io.grpc:grpc-protobuf:${Deps.grpcJavaVersion}")
api("com.google.protobuf:protobuf-kotlin:${Deps.protobufVersion}")
api(libs.protobuf.java)
api(libs.protobuf.kotlin)
api(libs.grpc.protobuf)

api("javax.annotation:javax.annotation-api:1.3.2")
api(libs.javax.annotation.api)

// generateTestProto needs compiler binary
compileOnly(project(":kert-grpc-compiler"))

testImplementation("io.grpc:grpc-stub:${Deps.grpcJavaVersion}")
testImplementation("io.grpc:grpc-netty:${Deps.grpcJavaVersion}")
testImplementation(libs.grpc.stub)
testImplementation(libs.grpc.netty)
}

protobuf {
generatedFilesBaseDir = "$projectDir/gen"
protoc {
artifact = "com.google.protobuf:protoc:${Deps.protobufVersion}"
artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.get()}"
}
plugins {
id("grpc-kert") {
path = "$rootDir/kert-grpc-compiler/build/exe/protoc-gen-grpc-kert${Consts.exeSuffix}"
}
// generate java version for performance comparison
id("grpc-java") {
artifact = "io.grpc:protoc-gen-grpc-java:${Deps.grpcJavaVersion}"
artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.grpc.get()}"
}
}
generateProtoTasks {
Expand Down
16 changes: 7 additions & 9 deletions kert-http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import build.*

description = "Kert HTTP support"

librarySupport()
configureLibrary()

dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Deps.kotlinVersion}")
api("org.jetbrains.kotlin:kotlin-reflect:${Deps.kotlinVersion}")
api("org.jetbrains.kotlin:kotlin-script-runtime:${Deps.kotlinVersion}")
api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${Deps.kotlinCoroutineVersion}")
api(libs.bundles.kotlin)

api("io.vertx:vertx-web:${Deps.vertxVersion}")
api("io.vertx:vertx-lang-kotlin-coroutines:${Deps.vertxVersion}")
api(libs.kotlinx.coroutines)
api(libs.kotlinx.coroutines.slf4j)

api("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:${Deps.kotlinCoroutineVersion}")
api(libs.vertx.web)
api(libs.vertx.lang.kotlin.coroutines)

testImplementation("io.vertx:vertx-web-client:${Deps.vertxVersion}")
testImplementation(libs.vertx.web.client)
}

0 comments on commit 301e4ef

Please sign in to comment.