@@ -21,9 +21,7 @@ fun resolveDependencies(depIds: List<String>, customRepos: List<MavenRepo> = emp
2121
2222 // Use cached classpath from previous run if present
2323 if (DEP_LOOKUP_CACHE_FILE .isFile()) {
24- val cache = DEP_LOOKUP_CACHE_FILE .
25- readLines().filter { it.isNotBlank() }.
26- associateBy({ it.split(" " )[0 ] }, { it.split(" " )[1 ] })
24+ val cache = DEP_LOOKUP_CACHE_FILE .readLines().filter { it.isNotBlank() }.associateBy({ it.split(" " )[0 ] }, { it.split(" " )[1 ] })
2725
2826 if (cache.containsKey(depsHash)) {
2927 return cache.get(depsHash)
@@ -34,62 +32,6 @@ fun resolveDependencies(depIds: List<String>, customRepos: List<MavenRepo> = emp
3432 if (loggingEnabled) System .err.print (" [kscript] Resolving dependencies..." )
3533 var hasLoggedDownload = false
3634
37- val depTags = depIds.map {
38- val splitDepId = it.split(" :" )
39-
40- if (! listOf (3 , 4 ).contains(splitDepId.size)) {
41- System .err.println (" [ERROR] Invalid dependency locator: '${it} '. Expected format is groupId:artifactId:version[:classifier]" )
42- quit(1 )
43- }
44-
45- """
46- <dependency>
47- <groupId>${splitDepId[0 ]} </groupId>
48- <artifactId>${splitDepId[1 ]} </artifactId>
49- <version>${splitDepId[2 ]} </version>
50- ${if (splitDepId.size == 4 ) " <classifier>" + splitDepId[3 ] + " <classifier>" else " " }
51- </dependency>
52- """
53- }
54-
55- // see https://github.com/holgerbrandl/kscript/issues/22
56- val repoTags = customRepos.map {
57- """
58- <repository>
59- <id>${it.id} </id>
60- <url>${it.url} </url>
61- </repository>
62- """
63-
64- }
65-
66- val pom = """
67- <?xml version="1.0" encoding="UTF-8"?>
68- <project xmlns="http://maven.apache.org/POM/4.0.0"
69- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
70- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
71-
72- <modelVersion>4.0.0</modelVersion>
73-
74- <groupId>kscript</groupId>
75- <artifactId>maven_template</artifactId>
76- <version>1.0</version>
77-
78- <repositories>
79- <repository>
80- <id>jcenter</id>
81- <url>http://jcenter.bintray.com/</url>
82- </repository>
83- ${repoTags.joinToString(" \n " )}
84- </repositories>
85-
86- <dependencies>
87- ${depTags.joinToString(" \n " )}
88- </dependencies>
89- </project>
90- """
91-
92-
9335 fun runMaven (pom : String , goal : String ): Iterable <String > {
9436 val temp = File .createTempFile(" __resdeps__temp__" , " _pom.xml" )
9537 temp.writeText(pom)
@@ -119,6 +61,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
11961 }).stdout.lines()
12062 }
12163
64+ val pom = buildPom(depIds, customRepos)
12265 val mavenResult = runMaven(pom, " dependency:build-classpath" )
12366
12467
@@ -143,8 +86,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
14386
14487 System .err.println (" [kscript] Generated pom file was:" )
14588 pom.lines()
146- // .map{it.prependIndent("[kscript] [pom] ")}
147- .forEach { System .err.println (it) }
89+ // .map{it.prependIndent("[kscript] [pom] ")}
90+ .forEach { System .err.println (it) }
14891 quit(1 )
14992 }
15093
@@ -167,4 +110,4 @@ object DependencyUtil {
167110 fun main (args : Array <String >) {
168111 System .err.println (resolveDependencies(args.toList(), loggingEnabled = false ))
169112 }
170- }
113+ }
0 commit comments