Maven-Dependency-Tree icon indicating copy to clipboard operation
Maven-Dependency-Tree copied to clipboard

🌲 Kotlin script to list transitive dependencies of a Maven artifact.

🌲 Maven Dependency Tree Demo

Kotlin script to list transitive dependencies of a Maven artifact.

Usage

$ kotlin tree.main.kts --help
Usage: tree.main.kts [ARGUMENTS] [OPTIONS]
Arguments: 
    artifact [groupId:artifactId:version] -> Name of the artifact to explore (optional)
Options: 
    --help, -h          -> Usage info
    --quiet, -q [false] -> Hide debug message
    --no-legend [false] -> Hide the legend
    --repository=<URL>  -> Maven repository (vararg) defaults to Maven Central

Simple dependency on Maven Central

$ kotlin tree.main.kts org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2 --repository=https://repo1.maven.org/maven2
🌲 Maven Dependency Tree

βš™οΈ Arguments: [org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2, --repository=https://repo1.maven.org/maven2]
πŸ“‘ Crawling POM files…
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core/1.6.2/kotlinx-coroutines-core-1.6.2.pom in 423.921752ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.6.2/kotlinx-coroutines-core-jvm-1.6.2.pom in 3.886530ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.6.21/kotlin-stdlib-jdk8-1.6.21.pom in 4.248533ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.6.21/kotlin-stdlib-common-1.6.21.pom in 2.873122ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.6.21/kotlin-stdlib-1.6.21.pom in 6.473750ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.6.21/kotlin-stdlib-jdk7-1.6.21.pom in 3.954230ms
βœ… https://repo1.maven.org/maven2/org/jetbrains/annotations/13.0/annotations-13.0.pom in 6.219047ms
⏱ Total duration: 666.792915ms

org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2
└─ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.2 (compile)
   β”œβ”€ org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21 (compile)
   β”‚  β”œβ”€ org.jetbrains.kotlin:kotlin-stdlib:1.6.21 (compile)
   β”‚  β”‚  β”œβ”€ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21 (compile)
   β”‚  β”‚  └─ org.jetbrains:annotations:13.0 (compile)
   β”‚  └─ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21 (compile)
   β”‚     └─ org.jetbrains.kotlin:kotlin-stdlib:1.6.21 (compile) ↩️
   └─ org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21 (compile) ↩️

πŸ”£ Legend:
- πŸ” Cyclic dependency
- ↩️ Already printed
- β›” Non resolvable
- πŸ’€ Failed to resolve

More complex dependency tree on multiple repositories

$ kotlin tree.main.kts androidx.core:core:1.8.0 --repository=https://dl.google.com/android/maven2 --repository=https://repo1.maven.org/maven2
🌲 Maven Dependency Tree

βš™οΈ Arguments: [androidx.core:core:1.8.0, --repository=https://dl.google.com/android/maven2, --repository=https://repo1.maven.org/maven2]
πŸ“‘ Crawling POM files…
βœ… https://dl.google.com/android/maven2/androidx/core/core/1.8.0/core-1.8.0.pom in 509.684913ms
βœ… https://dl.google.com/android/maven2/androidx/annotation/annotation/1.2.0/annotation-1.2.0.pom in 18.624724ms
βœ… https://dl.google.com/android/maven2/androidx/annotation/annotation-experimental/1.1.0/annotation-experimental-1.1.0.pom in 62.313017ms
βœ… https://dl.google.com/android/maven2/androidx/collection/collection/1.0.0/collection-1.0.0.pom in 20.174835ms
βœ… https://dl.google.com/android/maven2/androidx/concurrent/concurrent-futures/1.0.0/concurrent-futures-1.0.0.pom in 52.146949ms
βœ… https://dl.google.com/android/maven2/androidx/lifecycle/lifecycle-runtime/2.3.1/lifecycle-runtime-2.3.1.pom in 28.580292ms
βœ… https://dl.google.com/android/maven2/androidx/versionedparcelable/versionedparcelable/1.1.1/versionedparcelable-1.1.1.pom in 46.431111ms
❌ https://dl.google.com/android/maven2/junit/junit/4.12/junit-4.12.pom FileNotFoundException in 28.122588ms
βœ… https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.pom in 54.531166ms
βœ… https://dl.google.com/android/maven2/androidx/annotation/annotation/1.0.0/annotation-1.0.0.pom in 55.419471ms
❌ https://dl.google.com/android/maven2/com/google/guava/listenablefuture/1.0/listenablefuture-1.0.pom FileNotFoundException in 48.115922ms
βœ… https://repo1.maven.org/maven2/com/google/guava/listenablefuture/1.0/listenablefuture-1.0.pom in 4.110027ms
βœ… https://dl.google.com/android/maven2/androidx/annotation/annotation/1.1.0/annotation-1.1.0.pom in 57.136983ms
βœ… https://dl.google.com/android/maven2/androidx/lifecycle/lifecycle-common/2.3.1/lifecycle-common-2.3.1.pom in 55.194970ms
βœ… https://dl.google.com/android/maven2/androidx/arch/core/core-common/2.1.0/core-common-2.1.0.pom in 23.480057ms
βœ… https://dl.google.com/android/maven2/androidx/arch/core/core-runtime/2.1.0/core-runtime-2.1.0.pom in 55.992375ms
❌ https://dl.google.com/android/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom FileNotFoundException in 17.272216ms
βœ… https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom in 2.422317ms
⏱ Total duration: 1.303770532s

androidx.core:core:1.8.0
β”œβ”€ androidx.annotation:annotation:1.2.0 (compile)
β”œβ”€ androidx.annotation:annotation-experimental:1.1.0 (compile)
β”œβ”€ androidx.collection:collection:1.0.0 (runtime)
β”‚  β”œβ”€ junit:junit:4.12 (test)
β”‚  β”‚  └─ org.hamcrest:hamcrest-core:1.3
β”‚  └─ androidx.annotation:annotation:1.0.0 (compile)
β”œβ”€ androidx.concurrent:concurrent-futures:1.0.0 (runtime)
β”‚  β”œβ”€ com.google.guava:listenablefuture:1.0 (compile)
β”‚  └─ androidx.annotation:annotation:1.1.0 (compile)
β”œβ”€ androidx.lifecycle:lifecycle-runtime:2.3.1 (compile)
β”‚  β”œβ”€ androidx.lifecycle:lifecycle-common:2.3.1 (compile)
β”‚  β”‚  └─ androidx.annotation:annotation:1.1.0 (compile) ↩️
β”‚  β”œβ”€ androidx.arch.core:core-common:2.1.0 (compile)
β”‚  β”‚  └─ androidx.annotation:annotation:1.1.0 (compile) ↩️
β”‚  β”œβ”€ androidx.annotation:annotation:1.1.0 (compile) ↩️
β”‚  └─ androidx.arch.core:core-runtime:2.1.0 (runtime)
β”‚     β”œβ”€ androidx.annotation:annotation:1.1.0 (compile) ↩️
β”‚     └─ androidx.arch.core:core-common:[2.1.0] (compile) β›”
└─ androidx.versionedparcelable:versionedparcelable:1.1.1 (compile)
   β”œβ”€ androidx.annotation:annotation:1.1.0 (compile) ↩️
   └─ androidx.collection:collection:1.0.0 (compile)
      β”œβ”€ junit:junit:4.12 (test) ↩️
      └─ androidx.annotation:annotation:1.0.0 (compile) ↩️

πŸ”£ Legend:
- πŸ” Cyclic dependency
- ↩️ Already printed
- β›” Non resolvable
- πŸ’€ Failed to resolve

Credits

License

Copyright 2022 Simon Marquis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.