Created
October 6, 2024 07:21
-
-
Save SNWCreations/1cf3ace9bc15ce2b2d4e1170dd3c5095 to your computer and use it in GitHub Desktop.
Get files of all dependencies in your Java project which is using Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The code below is tested with Gradle 8.5, it works well in my project. | |
| // This Gist is licensed under MIT license. Feel free to copy it and use them. | |
| static Collection<File> getAllDependencyFiles(Project project) { | |
| var container = project.configurations | |
| List<Configuration> toScan = [ | |
| container.compileClasspath, | |
| container.runtimeClasspath | |
| ] | |
| Set<File> result = new HashSet<>() | |
| for (final def conf in toScan) { | |
| var collected = getAllDependencyFilesFromConf(conf) | |
| result.addAll(collected) | |
| } | |
| return result | |
| } | |
| static Collection<File> getAllDependencyFilesFromConf(Configuration conf) { | |
| Set<File> result = new HashSet<>() | |
| for (final def dep in conf.allDependencies) { | |
| Collection<File> collected | |
| if (dep instanceof ProjectDependency) { | |
| var depProj = dep.dependencyProject | |
| collected = getAllDependencyFiles(depProj) | |
| } else { | |
| collected = conf.files(dep) | |
| } | |
| result.addAll(collected) | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment