@@ -26,6 +26,83 @@ repositories {
2626 mavenCentral()
2727}
2828
29+ tasks. register(' printDepsTreeInJson' ) {
30+ doLast {
31+ configurations. compileClasspath. incoming. resolutionResult. allDependencies. each { depResult ->
32+ def from = depResult. from
33+ def requested = depResult. requested
34+
35+
36+ println groovy.json.JsonOutput . toJson([
37+ from : from. toString(),
38+ requested : requested. toString()
39+ ])
40+ }
41+ }
42+ }
43+
44+ tasks. register(' getURLDeps' ) {
45+ doFirst {
46+ println (" doing something" )
47+ configurations. compileClasspath. incoming. resolutionResult. allDependencies. each { dependency ->
48+ println (" dependency requested: " + dependency. requested)
49+ println (" dependency selected: " + dependency. properties. get(" selected" ))
50+ println (" dependency from: " + dependency. from)
51+ println (" dependency properties: " + dependency. properties)
52+ for (ArtifactRepository repository : repositories. asList()) {
53+ def url = repository. properties. get(' url' )
54+ println (url)
55+ var selected = dependency. properties. get(" selected" )
56+ // https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar
57+ def jarUrl = String . format(" %s%s/%s/%s/%s-%s.jar" , url. toString(),
58+ selected. replace(' .' , ' /' ), selected. name, dependency. from. version,
59+ dependency. from. name, dependency. from. version)
60+ try {
61+ def jarfile = new URL (jarUrl)
62+ def inStream = jarfile. openStream();
63+ if (inStream != null ) {
64+ println (String . format(" %s:%s:%s" , dependency. group, dependency. name, dependency. version)
65+ + " -> " + jarUrl)
66+ return
67+ }
68+ } catch (Exception ignored) {
69+ println (ignored. getMessage())
70+ }
71+ }
72+ }
73+ }
74+ }
75+
76+ tasks. register(' generateDependenciesJson' ) {
77+ doLast {
78+ def jsonOutput = " ["
79+ configurations. compileClasspath. resolvedConfiguration. firstLevelModuleDependencies. each { dep ->
80+ def addToJson
81+ addToJson = { resolvedDep ->
82+ jsonOutput + = " \n {"
83+ jsonOutput + = " \" groupId\" :\" ${ resolvedDep.module.id.group} \" ,\" artifactId\" :\" ${ resolvedDep.module.id.name} \" ,\" version\" :\" ${ resolvedDep.module.id.version} \" ,\" file\" :\" ${ resolvedDep.getModuleArtifacts()[0].file} \" "
84+ jsonOutput + = " ,\" dependencies\" :["
85+ if (resolvedDep. children. size() != 0 ) {
86+ resolvedDep. children. each { childResolvedDep ->
87+ if (resolvedDep in childResolvedDep. getParents() && childResolvedDep. getConfiguration() == ' compile' ) {
88+ addToJson(childResolvedDep)
89+ }
90+ }
91+ if (jsonOutput[-1 ] == ' ,' ) {
92+ jsonOutput = jsonOutput[0 .. -2 ]
93+ }
94+ }
95+ jsonOutput + = " ]},"
96+ }
97+ addToJson(dep)
98+ }
99+ if (jsonOutput[-1 ] == ' ,' ) {
100+ jsonOutput = jsonOutput[0 .. -2 ]
101+ }
102+ jsonOutput + = " ]"
103+ println jsonOutput
104+ }
105+ }
29106
30107dependencies {
31108
0 commit comments