Git Product home page Git Product logo

depstoml's Introduction

depstoml

CI

A CLI tool facilitating migration from buildSrc-hardcoded dependencies to Gradle version catalog TOML file in Kotlin projects

Installation

Download the depstoml-x.x.jar file from the latest GitHub release and launch it with corresponding arguments

Usage

$ java -jar depstoml-x.x.jar [OPTIONS] deps [toml]

Sample deps value: buildSrc/src/main/kotlin/Dependencies.kt

Sample toml value: gradle/libs.versions.toml

Options

  • -o, --order-lexicographically - if you want to sort the dependencies lexicographically
  • -r, --replace-usages - if you want to replace usages of old dependencies with new ones in build.gradle.kts files

Arguments

  • deps - path to Kotlin dependencies file
  • toml - generated libs.versions.toml file path (defaults to current directory)

Your Kotlin dependencies file in buildSrc (or build-logic, or whatever) is expected to be structured in 2 possible ways:

  1. versions grouped together with artifacts
object Dependencies {

    object Kotlin {

        private const val version = "1.8.21"
        private const val dateTimeVersion = "0.4.0"

        const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
        const val dateTime = "org.jetbrains.kotlinx:kotlinx-datetime:$dateTimeVersion"

        object Coroutines {

            private const val version = "1.6.4"

            const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
            const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$version"
        }
    }

    object Log {

        private const val version = "2.6.1"

        const val napier = "io.github.aakira:napier:$version"
    }

    object Plugins {

        private const val version = "1.8.21-1.0.11"

        const val ksp = "com.google.devtools.ksp:$version"
    }
}
  1. versions and artifacts separately
object Versions {

    object Kotlin {

        const val version = "1.8.21"
        const val dateTimeVersion = "0.4.0"

        object Coroutines {

            const val version = "1.6.4"
        }
    }

    object Log {

        const val version = "2.6.1"
    }

    object Plugins {

        const val kspVersion = "1.8.21-1.0.11"
    }
}

object Deps {

    object Kotlin {

        const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.version}"
        const val dateTime = "org.jetbrains.kotlinx:kotlinx-datetime:${Versions.Kotlin.dateTimeVersion}"

        object Coroutines {

            const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.Kotlin.Coroutines.version}"
            const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.Kotlin.Coroutines.version}"
        }
    }

    object Log {

        const val napier = "io.github.aakira:napier:${Versions.Log.version}"
    }

    object Plugins {

        const val ksp = "com.google.devtools.ksp:${Versions.Plugins.kspVersion}"
    }
}
! Note that the program can't parse complex logic with by lazy, fun etc.

Sample dependencies file 1 above will generate the following:

[versions]
kotlin-version = "1.8.21"
kotlin-date-time-version = "0.4.0"
kotlin-coroutines-version = "1.6.4"
log-version = "2.6.1"
plugins-version = "1.8.21-1.0.11"

[libraries]
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-version" }
kotlin-date-time = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlin-date-time-version" }
kotlin-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlin-coroutines-version" }
kotlin-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlin-coroutines-version" }
log-napier = { group = "io.github.aakira", name = "napier", version.ref = "log-version" }

[plugins]
plugins-ksp = { id = "com.google.devtools.ksp", version.ref = "plugins-version" }

Sample dependencies file 2 above will generate the following:

[versions]
kotlin-version = "1.8.21"
kotlin-date-time-version = "0.4.0"
kotlin-coroutines-version = "1.6.4"
log-version = "2.6.1"
plugins-ksp-version = "1.8.21-1.0.11"

[libraries]
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-version" }
kotlin-date-time = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlin-date-time-version" }
kotlin-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlin-coroutines-version" }
kotlin-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlin-coroutines-version" }
log-napier = { group = "io.github.aakira", name = "napier", version.ref = "log-version" }

[plugins]
plugins-ksp = { id = "com.google.devtools.ksp", version.ref = "plugins-ksp-version" }

depstoml's People

Contributors

overpas avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.