Gradle Dependencies Sorter: An Overview
Gradle Dependencies Sorter is a straightforward yet powerful tool designed to streamline the management of dependencies in Gradle build scripts. This Java Virtual Machine (JVM) Command-Line Interface (CLI) application and accompanying Gradle plugin are adept at organizing the clutter that often accumulates in build.gradle[.kts]
scripts, making them not only more readable but also easier to maintain. Below, we delve into its usage, along with insights into its development and distribution.
Key Features
-
CLI Tool: The CLI application allows users to sort dependencies across multiple paths or simply at the root of a project. It operates on both directories and individual build script files, giving developers the flexibility to organize their project dependencies effortlessly.
-
Gradle Plugin: For those who prefer working directly within the Gradle environment, the Gradle plugin offers a seamless solution to sort dependencies with easy integration into the existing build processes.
How to Use the CLI
The Gradle Dependencies Sorter’s CLI can be employed in various ways:
- Sort an entire repository using a simple command to navigate to the root directory.
- Tackle specific sections of a project, such as a subtree or individual files, by pointing the CLI to the desired paths.
- Check the sorting status of the current dependencies arrangement to ensure proper maintenance over time.
Examples of CLI Commands
./path/to/sort .
./path/to/sort features
./path/to/sort my/app/build.gradle[.kts] my/app2/build.gradle[.kts]
./path/to/sort -m check <paths>
Using the Gradle Plugin
To apply the plugin:
First, ensure it is included in your build.gradle[.kts]
file:
plugins {
id("com.squareup.sort-dependencies") version "<<version>>"
}
Sorting and Checking
Sorting dependencies can easily be accomplished via:
./gradlew :my:app:sortDependencies
To verify if the dependencies are sorted correctly, the following Gradle task can be initiated:
./gradlew :my:app:checkSortDependencies
The sorting check integrates with the Gradle ‘check’ task, allowing it to run automatically during the verification phase of your build.
Testing Functionality
The project supports a basic testing task that ensures everything is functioning as expected:
./gradlew check
Building and Distribution
For those interested in customizing or contributing to the project, the Gradle Dependencies Sorter is fully buildable and distributable:
- Publish to Maven Local: Use
./gradlew publishToMavenLocal
to push project artifacts to~/.m2/repository/
. - Create a Zip Distribution: The command
./gradlew :app:shadowDistZip
packages the application into a zip for easy distribution. - Install the CLI: With
./gradlew :app:installShadowDist
, the application can be installed locally for easy CLI access.
Acknowledgments
The project has been shaped by contributions from a team of developers whose dedication is instrumental to its success. Notably, contributions before the open-source transition were made by autonomousapps, darshanparajuli, and holmes.
Licensing
Gradle Dependencies Sorter is open-sourced under the Apache License, Version 2.0, which allows developers to freely use, modify, and distribute the software in compliance with the license terms.
In summary, Gradle Dependencies Sorter is an essential tool to aid developers in maintaining clean and efficiently organized build scripts, enhancing the development workflow and reducing the potential for error due to dependency mismanagement.