Skip to content

Commit

Permalink
Migrate dependencies.yml to Gradle's version catalogs (#4353)
Browse files Browse the repository at this point in the history
Motivation:

We can declare dependency versions using `dependencies.yml` and share them
across multiple projects. It is useful to manage the versions of various
dependencies. However, we can't define different versions of a module.
Because the unique keys in `dependencies.yml` are `moduleId:artifactId`.

This limitation makes it difficult to manage compatibility between
different versions of a library. For example, okhttp v4 is required to
test `it:okhttp` and okhttp v3 is required to run `retrofit2` module.

Gradle introduced a new way to [share dependency versions between projects](https://docs.gradle.org/current/userguide/platforms.html).
The unique key of version catalogs is a user-defined alias so we can
define multiple versions of a module using different aliases.

Version catalogs do not allow extra properties on `libs.versions.toml`.
It only allows some properties for versions and modules.
`dependencies.yml` not only manages versions but also manages metadata
for a module such as relocations, exclusions and Javadoc links.

I wanted to take advantage of both. We need a version manager that
supports version catalogs based on aliases, and the ability to add the
metadata. As a result, I implemented to add our own dependency mechanism
using `dependencies.toml` that is fully compatible with Gradle's version
catalogs and understands relocations, exclusions and Javadoc links
declarations.

Modifications:

- Migrate `dependencies.yml` to `dependencies.toml`
- Rename `common-dependences.gradle` to `common-dependences-lagacy.gradle` 
  for backward compatibility with `dependencies.yml`
  - Newly added `common-dependences.gradle` handles the dependencies declared by `dependencies.toml`
- Add `version-catalog.gradle` that parses `dependencies.toml` and builds:
  - Library and BOM version catalogs
  - relocations
  - exclusions
  - Javadoc links
- Migrate all dependencies defined in `build.gradle` files to the new version catalog API.

Result:

Fixes #4120
  • Loading branch information
ikhoon committed Aug 1, 2022
1 parent ff11efd commit 0d3fa08
Show file tree
Hide file tree
Showing 107 changed files with 2,294 additions and 1,524 deletions.
2 changes: 1 addition & 1 deletion annotation-processor/build.gradle
@@ -1,3 +1,3 @@
dependencies {
testImplementation 'org.jooq:joor'
testImplementation libs.joor
}
2 changes: 1 addition & 1 deletion benchmarks/ghz/build.gradle
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
implementation project(':core')
implementation project(':grpc')
implementation 'javax.annotation:javax.annotation-api'
implementation libs.javax.annotation
}

application {
Expand Down
33 changes: 10 additions & 23 deletions benchmarks/jmh/build.gradle
@@ -1,42 +1,29 @@
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "me.champeau.jmh:jmh-gradle-plugin:${managedVersions['me.champeau.jmh:jmh-gradle-plugin']}"
}
plugins {
alias libs.plugins.jmh
}

apply plugin: 'me.champeau.jmh'

dependencies {
implementation project(':grpc')
implementation project(':grpc-protocol')
implementation project(':retrofit2')
implementation project(':thrift0.16')
implementation project(':kotlin')

implementation("com.squareup.okhttp3:okhttp") {
version {
// Will fail the build if the override doesn't work
strictly '3.14.9'
}
}
implementation 'com.squareup.retrofit2:converter-jackson'
implementation 'com.google.protobuf:protobuf-java-util'
implementation 'io.grpc:grpc-okhttp'
implementation 'io.grpc:grpc-netty-shaded'
implementation 'org.awaitility:awaitility'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
implementation libs.retrofit2.converter.jackson
implementation libs.protobuf.java.util
implementation libs.grpc.okhttp
implementation libs.grpc.netty.shaded
implementation libs.awaitility
implementation libs.kotlin.coroutines.core

jmh "pl.project13.scala:sbt-jmh-extras:${managedVersions['pl.project13.scala:sbt-jmh-extras']}"
jmh libs.jmh.extras

implementation project(':testing-internal')
}

jmh {
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
jmhVersion = managedVersions['org.openjdk.jmh:jmh-core']
jmhVersion = libs.versions.jmh.get()

def jmhIncludes = rootProject.findProperty('jmh.includes')
if (jmhIncludes) {
Expand Down
8 changes: 4 additions & 4 deletions brave/build.gradle
@@ -1,8 +1,8 @@
dependencies {
api 'io.zipkin.brave:brave'
api 'io.zipkin.brave:brave-instrumentation-http'
api libs.brave
api libs.brave.instrumentation.http

testImplementation project(':thrift0.16')
testImplementation 'io.zipkin.brave:brave-context-slf4j'
testImplementation 'io.zipkin.brave:brave-instrumentation-http-tests'
testImplementation libs.brave.context.slf4j
testImplementation libs.brave.instrumentation.http.tests
}
2 changes: 1 addition & 1 deletion bucket4j/build.gradle
@@ -1,4 +1,4 @@
dependencies {
// Bucket4j - rate-limiting library based on Token-Bucket algorithm
implementation 'com.github.vladimir-bukhtoyarov:bucket4j-core'
implementation libs.bucket4j
}
82 changes: 39 additions & 43 deletions build.gradle
Expand Up @@ -11,15 +11,12 @@ buildscript {
}

plugins {
id 'com.google.osdetector' version '1.6.2' apply false
id 'cz.alenkacz.gradle.scalafmt' version '1.16.2' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
// If you want to change `org.jetbrains.kotlin.jvm` version,
// you also need to change `org.jetbrains.kotlin:kotlin-allopen` version in `dependencies.yml`.
id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
id 'org.jlleitschuh.gradle.ktlint' version '10.1.0' apply false

id 'net.ltgt.errorprone' version '2.0.2' apply false
alias libs.plugins.osdetector apply false
alias libs.plugins.scalafmt apply false
alias libs.plugins.nexus.publish
alias libs.plugins.kotlin apply false
alias libs.plugins.ktlint apply false
alias libs.plugins.errorprone apply false
}

allprojects {
Expand Down Expand Up @@ -105,7 +102,7 @@ configure(projectsWithFlags('java')) {
apply plugin: 'net.ltgt.errorprone'

dependencies {
errorprone 'com.google.errorprone:error_prone_core'
errorprone libs.errorprone.core
}

tasks.withType(JavaCompile) {
Expand All @@ -124,59 +121,58 @@ configure(projectsWithFlags('java')) {
testImplementation project(':testing-internal')

// completable-futures
implementation 'com.spotify:completable-futures'
implementation libs.futures.completable

// Errorprone
compileOnly 'com.google.errorprone:error_prone_annotations'
testImplementation 'com.google.errorprone:error_prone_annotations'
compileOnly libs.errorprone.annotations
testImplementation libs.errorprone.annotations

// FastUtil
implementation 'it.unimi.dsi:fastutil'
implementation libs.fastutil

// Guava
implementation 'com.google.guava:guava'
implementation libs.guava

// J2ObjC annotations
compileOnly 'com.google.j2objc:j2objc-annotations'
compileOnly libs.j2objc

// JSR305
implementation 'com.google.code.findbugs:jsr305'
implementation libs.findbugs

// JCTools
implementation 'org.jctools:jctools-core'
implementation libs.jctools

// Jetty ALPN support
compileOnly 'org.eclipse.jetty.alpn:alpn-api'
compileOnly libs.jetty.alpn.api

// Logging
implementation 'org.slf4j:slf4j-api'
testImplementation 'org.slf4j:jul-to-slf4j'
testImplementation 'ch.qos.logback:logback-classic'
['jcl-over-slf4j', 'log4j-over-slf4j'].each {
testRuntimeOnly "org.slf4j:$it"
}
implementation libs.slf4j.api
testImplementation libs.slf4j.jul.to.slf4j
testImplementation libs.logback
testRuntimeOnly libs.slf4j.jcl.over.slf4j
testRuntimeOnly libs.slf4j.log4j.over.slf4j

// Reflections
implementation 'org.reflections:reflections'
implementation libs.reflections

// Test-time dependencies
testImplementation 'com.google.guava:guava-testlib'
testImplementation 'junit:junit'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.platform:junit-platform-commons'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testImplementation 'net.javacrumbs.json-unit:json-unit'
testImplementation 'net.javacrumbs.json-unit:json-unit-fluent'
testImplementation 'org.awaitility:awaitility'
testRuntimeOnly 'org.checkerframework:checker-compat-qual' // Required by guava-testlib
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.apache.httpcomponents:httpclient'
testImplementation 'org.hamcrest:hamcrest'
testImplementation 'org.hamcrest:hamcrest-library'
testImplementation libs.guava.testlib
testImplementation libs.junit4
testImplementation libs.junit5.jupiter.api
testImplementation libs.junit5.jupiter.params
testRuntimeOnly libs.junit5.platform.commons
testRuntimeOnly libs.junit5.platform.launcher
testRuntimeOnly libs.junit5.jupiter.engine
testRuntimeOnly libs.junit5.vintage.engine
testImplementation libs.json.unit
testImplementation libs.json.unit.fluent
testImplementation libs.awaitility
testRuntimeOnly libs.checkerframework // Required by guava-testlib
testImplementation libs.assertj
testImplementation libs.mockito
testImplementation libs.apache.httpclient
testImplementation libs.hamcrest
testImplementation libs.hamcrest.library
}

tasks.withType(JavaCompile) { task ->
Expand Down
6 changes: 3 additions & 3 deletions consul/build.gradle
Expand Up @@ -10,17 +10,17 @@ buildscript {
mavenCentral()
}
dependencies {
classpath "com.pszymczyk.consul:embedded-consul:${managedVersions['com.pszymczyk.consul:embedded-consul']}"
classpath libs.consul
}
}

dependencies {
// Embedded Consul
testImplementation 'com.pszymczyk.consul:embedded-consul'
testImplementation libs.consul

// Embedded Consul removed Groovy from transitive dependencies
// https://github.com/pszymczyk/embedded-consul/pull/102
testImplementation 'org.codehaus.groovy:groovy-xml'
testImplementation libs.groovy.xml
}

task consulBinary {
Expand Down
69 changes: 35 additions & 34 deletions core/build.gradle
Expand Up @@ -90,70 +90,71 @@ dependencies {
}

// Logging decorators expose slf4j in API
api 'org.slf4j:slf4j-api'
api libs.slf4j.api

// cglib
testImplementation 'cglib:cglib'
testImplementation libs.cglib

// Caffeine
implementation 'com.github.ben-manes.caffeine:caffeine'
implementation libs.caffeine

// Jackson
[ 'jackson-core', 'jackson-annotations', 'jackson-databind' ].each {
api "com.fasterxml.jackson.core:$it"
}
api libs.jackson.core
api libs.jackson.annotations
api libs.jackson.databind

// Micrometer and other metric-related stuff
api 'io.micrometer:micrometer-core'
optionalApi 'io.micrometer:micrometer-registry-prometheus'
optionalApi 'io.dropwizard.metrics:metrics-core'
optionalApi 'io.prometheus:simpleclient_common'
api libs.micrometer.core
optionalApi libs.micrometer.prometheus
optionalApi libs.dropwizard.metrics.core
optionalApi libs.prometheus

// Netty
[ 'netty-transport', 'netty-codec-http2', 'netty-codec-haproxy', 'netty-resolver-dns' ].each {
api "io.netty:$it"
}
implementation "io.netty:netty-resolver-dns-native-macos:${managedVersions['io.netty:netty-bom']}:osx-x86_64"
implementation "io.netty:netty-resolver-dns-native-macos:${managedVersions['io.netty:netty-bom']}:osx-aarch_64"
implementation "io.netty:netty-transport-native-unix-common:${managedVersions['io.netty:netty-bom']}:linux-x86_64"
implementation "io.netty:netty-transport-native-epoll:${managedVersions['io.netty:netty-bom']}:linux-x86_64"
api libs.netty.transport
api libs.netty.codec.haproxy
api libs.netty.codec.http2
api libs.netty.resolver.dns
implementation(libs.netty.transport.native.unix.common) { artifact { classifier = "linux-x86_64" } }
implementation(libs.netty.transport.native.epoll) { artifact { classifier = "linux-x86_64" } }
implementation(libs.netty.resolver.dns.native.macos) { artifact { classifier = "osx-x86_64" } }
implementation(libs.netty.resolver.dns.native.macos) { artifact { classifier = "osx-aarch_64" } }

// Note that tcnative now needs explicit classifiers
// Related: https://github.com/netty/netty-tcnative/pull/709
[ 'linux-x86_64', 'linux-aarch_64', 'osx-x86_64', 'osx-aarch_64', 'windows-x86_64' ].each {
implementation(group: 'io.netty', name: 'netty-tcnative-boringssl-static', classifier: it)
['linux-x86_64', 'linux-aarch_64', 'osx-x86_64', 'osx-aarch_64', 'windows-x86_64'].each { arch ->
implementation(libs.netty.tcnative.boringssl) { artifact { classifier = arch } }
}
implementation 'io.netty:netty-handler-proxy'
optionalImplementation "io.netty.incubator:netty-incubator-transport-native-io_uring:${managedVersions['io.netty.incubator:netty-incubator-transport-native-io_uring']}:linux-x86_64"
implementation libs.netty.handler.proxy
optionalImplementation(libs.netty.io.uring) { artifact { classifier = "linux-x86_64" } }

// TestNG
testImplementation 'org.testng:testng'
testImplementation libs.testng

// JUnit Pioneer
testImplementation 'org.junit-pioneer:junit-pioneer'
testImplementation libs.junit.pioneer

// Reactive Streams
api 'org.reactivestreams:reactive-streams'
testImplementation 'org.reactivestreams:reactive-streams-tck'
api libs.reactivestreams
testImplementation libs.reactivestreams.tck

// Do not upgrade to Scala 2.13.x that causes 'java.lang.ClassNotFoundException: scala.Serializable'
// See https://github.com/scala/bug/issues/11832#issuecomment-568185023
// If needed, you should consider to add 'armeria-scala' module.
optionalImplementation 'org.scala-lang:scala-library:2.12.15'
optionalImplementation libs.scala.v212

// Bouncy Castle
implementation 'org.bouncycastle:bcpkix-jdk15on'
implementation 'org.bouncycastle:bcprov-jdk15on'
implementation 'org.bouncycastle:bcutil-jdk15on'
implementation libs.bouncycastle.bcpkix
implementation libs.bouncycastle.bcprov
implementation libs.bouncycastle.bcutil

// Jetty, for testing interoperability with other servers.
testImplementation 'org.eclipse.jetty:jetty-webapp'
testImplementation libs.jetty94.webapp

// Brotli
implementation 'com.aayushatharva.brotli4j:brotli4j'
optionalImplementation 'com.aayushatharva.brotli4j:native-linux-x86_64'
optionalImplementation 'com.aayushatharva.brotli4j:native-osx-x86_64'
optionalImplementation 'com.aayushatharva.brotli4j:native-windows-x86_64'
implementation libs.brotli4j
optionalImplementation libs.brotli4j.linux
optionalImplementation libs.brotli4j.osx
optionalImplementation libs.brotli4j.windows
}

if (!rootProject.hasProperty('noWeb')) {
Expand Down

0 comments on commit 0d3fa08

Please sign in to comment.