From e2bbf68f2b91760ab0d8f714d3314dd91d2005fd Mon Sep 17 00:00:00 2001 From: Danilo Herrera Date: Fri, 2 Sep 2022 21:45:25 -0400 Subject: [PATCH] Migrate to version catalogs --- build.gradle | 12 ++++----- dependencies.gradle | 18 ------------- gradle/libs.versions.toml | 27 +++++++++++++++++++ mosaic-gradle-plugin/build.gradle | 8 +++--- .../src/test/fixture/counter/build.gradle | 6 ++--- .../jakewharton/mosaic/gradle/FixtureTest.kt | 2 +- mosaic-runtime/build.gradle | 10 +++---- samples/build.gradle | 4 +-- samples/settings.gradle | 8 ++++++ 9 files changed, 53 insertions(+), 42 deletions(-) delete mode 100644 dependencies.gradle create mode 100644 gradle/libs.versions.toml diff --git a/build.gradle b/build.gradle index 58e5e5a6..23a2d995 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,14 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { - apply from: 'dependencies.gradle' - dependencies { - classpath deps.kotlinGradlePlugin + classpath libs.kotlin.gradlePlugin // We don't use this dependency directly. However, we reference a type from the Kotlin Gradle // plugin whose classloading causes com.android.build.gradle.api.BaseVariant to also be loaded. - classpath 'com.android.tools.build:gradle:7.2.2' - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.13.0' - classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.7.10' - classpath 'com.github.gmazzo:gradle-buildconfig-plugin:3.1.0' + classpath libs.android.gradlePlugin + classpath libs.maven.publish.gradlePlugin + classpath libs.dokka.gradlePlugin + classpath libs.buildconfig.gradlePlugin } repositories { mavenCentral() diff --git a/dependencies.gradle b/dependencies.gradle deleted file mode 100644 index dba97a67..00000000 --- a/dependencies.gradle +++ /dev/null @@ -1,18 +0,0 @@ -buildscript { - ext.versions = [ - 'kotlin': '1.7.10', - 'kotlinxCoroutines': '1.6.1', - 'composeCompiler': '1.3.0', - ] - ext.deps = [ - 'androidxComposeCompiler': "androidx.compose.compiler:compiler:${versions.composeCompiler}", - 'kotlinCompiler': "org.jetbrains.kotlin:kotlin-compiler:${versions.kotlin}", - 'kotlinGradlePlugin': "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}", - 'kotlinxCoroutinesCore': "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinxCoroutines}", - 'kotlinxCoroutinesTest': "org.jetbrains.kotlinx:kotlinx-coroutines-test:${versions.kotlinxCoroutines}", - 'jetbrainsComposeRuntime': 'org.jetbrains.compose.runtime:runtime:1.1.1', - 'junit': 'junit:junit:4.13.2', - 'truth': 'com.google.truth:truth:1.1.3', - 'jansi': 'org.fusesource.jansi:jansi:2.4.0', - ] -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..a87bb347 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,27 @@ +[versions] +kotlin = "1.7.10" +androidGradlePlugin = "7.2.2" +mavenPublishPlugin = "0.13.0" +buildConfigPlugin = "3.1.0" +kotlinxCoroutines = "1.6.1" +composeCompiler = "1.3.0" +composeRuntime = "1.1.1" +junit4 = "4.13.2" +truth = "1.1.3" +jansi = "2.4.0" + +[libraries] +kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" } +android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } +maven-publish-gradlePlugin = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "mavenPublishPlugin" } +dokka-gradlePlugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "kotlin" } +buildconfig-gradlePlugin = { group = "com.github.gmazzo", name = "gradle-buildconfig-plugin", version.ref = "buildConfigPlugin" } +androidx-compose-compiler = { group = "androidx.compose.compiler", name = "compiler", version.ref = "composeCompiler" } +kotlin-compiler = { group = "org.jetbrains.kotlin", name = "kotlin-compiler", version.ref = "kotlin" } +kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" } +kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" } +jetbrains-compose-runtime = { group = "org.jetbrains.compose.runtime", name = "runtime", version.ref = "composeRuntime" } +junit4 = { group = "junit", name = "junit", version.ref = "junit4" } +truth = { group = "com.google.truth", name = "truth", version.ref = "truth" } +jansi = { group = "org.fusesource.jansi", name = "jansi", version.ref = "jansi" } + diff --git a/mosaic-gradle-plugin/build.gradle b/mosaic-gradle-plugin/build.gradle index 03e6db34..1393fec4 100644 --- a/mosaic-gradle-plugin/build.gradle +++ b/mosaic-gradle-plugin/build.gradle @@ -5,10 +5,10 @@ apply plugin: 'com.github.gmazzo.buildconfig' dependencies { compileOnly gradleApi() - compileOnly deps.kotlinGradlePlugin + compileOnly libs.kotlin.gradlePlugin - testImplementation deps.junit - testImplementation deps.truth + testImplementation libs.junit4 + testImplementation libs.truth testImplementation gradleTestKit() } @@ -35,6 +35,6 @@ buildConfig { } packageName('com.jakewharton.mosaic.gradle') - buildConfigField("String", "composeCompilerVersion", "\"${versions.composeCompiler}\"") + buildConfigField("String", "composeCompilerVersion", "\"${libs.versions.composeCompiler.get()}\"") buildConfigField("String", "mosaicVersion", "\"${project.version}\"") } diff --git a/mosaic-gradle-plugin/src/test/fixture/counter/build.gradle b/mosaic-gradle-plugin/src/test/fixture/counter/build.gradle index 2f9cfe29..8c3346be 100644 --- a/mosaic-gradle-plugin/src/test/fixture/counter/build.gradle +++ b/mosaic-gradle-plugin/src/test/fixture/counter/build.gradle @@ -1,8 +1,6 @@ buildscript { - apply from: "../../../../../dependencies.gradle" - dependencies { - classpath deps.kotlinGradlePlugin + classpath libs.kotlin.gradlePlugin classpath "com.jakewharton.mosaic:mosaic-gradle-plugin:${mosaicVersion}" } repositories { @@ -17,7 +15,7 @@ apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'com.jakewharton.mosaic' dependencies { - testImplementation deps.junit + testImplementation libs.junit4 } repositories { diff --git a/mosaic-gradle-plugin/src/test/kotlin/com/jakewharton/mosaic/gradle/FixtureTest.kt b/mosaic-gradle-plugin/src/test/kotlin/com/jakewharton/mosaic/gradle/FixtureTest.kt index 0a1c58aa..24be72a2 100644 --- a/mosaic-gradle-plugin/src/test/kotlin/com/jakewharton/mosaic/gradle/FixtureTest.kt +++ b/mosaic-gradle-plugin/src/test/kotlin/com/jakewharton/mosaic/gradle/FixtureTest.kt @@ -25,7 +25,7 @@ class FixtureTest( @Test fun todo() { val fixtureDir = File(fixturesDir, fixtureName) val gradleRoot = File(fixtureDir, "gradle").also { it.mkdir() } - File("../gradle/wrapper").copyRecursively(File(gradleRoot, "wrapper"), true) + File("../gradle").copyRecursively(File(gradleRoot.path), true) GradleRunner.create() .withProjectDir(fixtureDir) diff --git a/mosaic-runtime/build.gradle b/mosaic-runtime/build.gradle index 93fb0e93..4b967c3e 100644 --- a/mosaic-runtime/build.gradle +++ b/mosaic-runtime/build.gradle @@ -4,11 +4,11 @@ apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'com.vanniktech.maven.publish' dependencies { - api deps.jetbrainsComposeRuntime - implementation deps.jansi + api libs.jetbrains.compose.runtime + implementation libs.jansi - testImplementation deps.junit - testImplementation deps.truth + testImplementation libs.junit4 + testImplementation libs.truth - add(KotlinPluginKt.PLUGIN_CLASSPATH_CONFIGURATION_NAME, deps.androidxComposeCompiler) + add(KotlinPluginKt.PLUGIN_CLASSPATH_CONFIGURATION_NAME, libs.androidx.compose.compiler) } diff --git a/samples/build.gradle b/samples/build.gradle index 735fb39b..1e360039 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -1,8 +1,6 @@ buildscript { - apply from: '../dependencies.gradle' - dependencies { - classpath deps.kotlinGradlePlugin + classpath libs.kotlin.gradlePlugin // Normally you would declare a version here, but we use dependency substitution in // settings.gradle to use the version built from inside the repo. diff --git a/samples/settings.gradle b/samples/settings.gradle index d8f01c8a..3b5357ae 100644 --- a/samples/settings.gradle +++ b/samples/settings.gradle @@ -8,3 +8,11 @@ includeBuild('..') { substitute module('com.jakewharton.mosaic:mosaic-runtime') using project(':mosaic-runtime') } } + +dependencyResolutionManagement { + versionCatalogs { + libs { + from(files("../gradle/libs.versions.toml")) + } + } +}