@@ -16,8 +16,10 @@ internal class GradleClassPathResolver(private val path: Path, private val inclu
16
16
override val resolverType: String = " Gradle"
17
17
override val classpath: Set <Path > get() {
18
18
val projectDirectory = path.getParent()
19
- val tasks = listOf (" kotlinLSPProjectDeps" ) + (if (includeKotlinDSL) listOf (" kotlinLSPKotlinDSLDeps" ) else emptySet())
20
- return readDependenciesViaGradleCLI(projectDirectory, tasks)
19
+ val scripts = listOf (" projectClassPathFinder.gradle" ) + listOf (" kotlinDSLClassPathFinder.gradle" ).takeIf { includeKotlinDSL }.orEmpty()
20
+ val tasks = listOf (" kotlinLSPProjectDeps" ) + listOf (" kotlinLSPKotlinDSLDeps" ).takeIf { includeKotlinDSL }.orEmpty()
21
+
22
+ return readDependenciesViaGradleCLI(projectDirectory, scripts, tasks)
21
23
.apply { if (isNotEmpty()) LOG .info(" Successfully resolved dependencies for '${projectDirectory.fileName} ' using Gradle" ) }
22
24
}
23
25
@@ -29,7 +31,7 @@ internal class GradleClassPathResolver(private val path: Path, private val inclu
29
31
}
30
32
}
31
33
32
- private fun createTemporaryGradleFile ( deleteOnExit : Boolean = false): File {
34
+ private fun gradleScriptToTempFile ( scriptName : String , deleteOnExit : Boolean = false): File {
33
35
val config = File .createTempFile(" classpath" , " .gradle" )
34
36
if (deleteOnExit) {
35
37
config.deleteOnExit()
@@ -38,7 +40,7 @@ private fun createTemporaryGradleFile(deleteOnExit: Boolean = false): File {
38
40
LOG .debug(" Creating temporary gradle file {}" , config.absolutePath)
39
41
40
42
config.bufferedWriter().use { configWriter ->
41
- ClassLoader .getSystemResourceAsStream(" classpathFinder.gradle " ).bufferedReader().use { configReader ->
43
+ ClassLoader .getSystemResourceAsStream(scriptName ).bufferedReader().use { configReader ->
42
44
configReader.copyTo(configWriter)
43
45
}
44
46
}
@@ -58,15 +60,18 @@ private fun getGradleCommand(workspace: Path): Path {
58
60
}
59
61
}
60
62
61
- private fun readDependenciesViaGradleCLI (projectDirectory : Path , gradleTasks : List <String >): Set <Path > {
63
+ private fun readDependenciesViaGradleCLI (projectDirectory : Path , gradleScripts : List < String >, gradleTasks : List <String >): Set <Path > {
62
64
LOG .info(" Resolving dependencies for '{}' through Gradle's CLI using tasks {}..." , projectDirectory.fileName, gradleTasks)
63
- val tmpFile = createTemporaryGradleFile(deleteOnExit = false ).toPath()
65
+
66
+ val tmpScripts = gradleScripts.map { gradleScriptToTempFile(it, deleteOnExit = false ).toPath().toAbsolutePath() }
64
67
val gradle = getGradleCommand(projectDirectory)
65
- val command = " $gradle -I ${tmpFile.toAbsolutePath()} ${gradleTasks.joinToString(separator = " " )} --console=plain"
68
+
69
+ val command = " $gradle ${tmpScripts.map { " -I $it " }.joinToString(" " )} ${gradleTasks.joinToString(" " )} --console=plain"
66
70
val dependencies = findGradleCLIDependencies(command, projectDirectory)
67
71
?.also { LOG .debug(" Classpath for task {}" , it) }
68
72
.orEmpty()
69
- Files .delete(tmpFile)
73
+
74
+ tmpScripts.forEach(Files ::delete)
70
75
return dependencies
71
76
}
72
77
0 commit comments