Simple script helping with migration to a new Gradle Central declaration of dependencies in TOML file.
This script was used just for my internal purposes. I made it available, just because it can be useful for somebody else. It is not the best way how to do it. It is just a dirty script of how to do it fast. The configuration is possible by variables inside of the script.
Warning: Script is not compatible with gradle configuration cache. Please use org.gradle.unsafe.configuration-cache=false i gradle.properties or --no-configuration-cache from command line to disabled it.
- Generate TOML file from existing multi-module project dependencies.
- Automatically generate
[versions]
block inside of TOML based on the same version. - Automatically generate alias inside of TOML (customizable).
- Replace classic dependencies with aliases inside of TOML file.
- Simple Groovy to Kotlin conversion based on GradleKotlinConverter.
- Allows converting classic dependency with included version variable into plain form (useful for Kotlin conversion).
- Gradle 7.0+ with centralized dependency support. The script itself will work on Gradle 6.7+, but you need at least 6.9 to use the central dependencies mechanism.
- You need to have dependency declaration in this format:
"com.squareup.okhttp3:okhttp:1.0.0"
or with some variable like"com.squareup.okhttp3:okhttp:${rootProject.ext.okhttpLibVersion}"
, different declaration format are not supported.
- Copy file tomldeps.gradle.kts to root of your project and put this to the end of your root build.gradle.kts:
apply(from = "tomldeps.gradle.kts")
- Change the
operation
variable inside of the script toGENERATE_TOML
. - Run
gradlew
. - Check generated
gradle/libs.versions.toml
. - If you are not satisfied with aliases you can modify
generateAlias
function inside of the script and then you can rungradlew
again. - You can do manual changes in TOML file, but don't forgot to change the operation back to
NOTHING
to avoid overridden by the next run ofgradlew
. - If you are satisfied with TOML file, change
operation
toREPLACE_DEPS_BY_TOML
a rungradlew
again. - You can now delete
apply
from your root build script and delete the script.
By default script will always create a copy of your build script, you can control it by replaceOriginalFiles
variable.
Build scripts in Groovytomldeps.gradle.kts
tomldeps.gradle.kts Steps are the same as for script in Kotlin, but you need to do a few additional things.
- Copy file tomldeps.gradle.kts to root of your project and put this to the end of your root build.gradle.kts:
apply from: 'tomldeps.gradle.kts'
. - Change the
operation
variable inside of the script toGENERATE_TOML
. - Change
inputFilesName
tobuild.gradle
only and rungradlew
once to do a conversion to.kts
. - Replace old
build.gradle
files with converted onebuild.gradle.kts
you can do it file by file, to keep project buildable all the time. Automatic to Kotlin conversion is very simple, just basic stuff. In some cases, it can even break something. You definitely need to finish conversion manually. - Continue with steps 4. to 6. of "Build scripts already in Kotlin".
- Change
inputFilesName
back tobuild.gradle.kts
- Continue with steps 7. and 8. of "Build scripts already in Kotlin".
If you want to to do to Kotlin conversion completely manually change doToKotlinConversion
to false
.