@@ -10,15 +10,19 @@ import java.nio.file.Files
10
10
import java.nio.file.Path
11
11
import java.nio.file.Paths
12
12
13
- internal class GradleClassPathResolver (private val path : Path , private val includeKotlinDSL : Boolean ): ClassPathResolver {
13
+ internal class GradleClassPathResolver (
14
+ private val path : Path ,
15
+ private val includeKotlinDSL : Boolean ,
16
+ private val useCompileClasspath : Boolean
17
+ ): ClassPathResolver {
14
18
override val resolverType: String = " Gradle"
15
19
private val projectDirectory: Path get() = path.parent
16
20
17
21
override val classpath: Set <ClassPathEntry > get() {
18
22
val scripts = listOf (" projectClassPathFinder.gradle" )
19
23
val tasks = listOf (" kotlinLSPProjectDeps" )
20
24
21
- return readDependenciesViaGradleCLI(projectDirectory, scripts, tasks)
25
+ return readDependenciesViaGradleCLI(projectDirectory, scripts, tasks, useCompileClasspath )
22
26
.apply { if (isNotEmpty()) LOG .info(" Successfully resolved dependencies for '${projectDirectory.fileName} ' using Gradle" ) }
23
27
.map { ClassPathEntry (it, null ) }.toSet()
24
28
}
@@ -38,9 +42,15 @@ internal class GradleClassPathResolver(private val path: Path, private val inclu
38
42
39
43
companion object {
40
44
/* * Create a Gradle resolver if a file is a pom. */
41
- fun maybeCreate (file : Path ): GradleClassPathResolver ? =
45
+ fun maybeCreate (file : Path , options : ResolverOptions ): GradleClassPathResolver ? =
42
46
file.takeIf { file.endsWith(" build.gradle" ) || file.endsWith(" build.gradle.kts" ) }
43
- ?.let { GradleClassPathResolver (it, includeKotlinDSL = file.toString().endsWith(" .kts" )) }
47
+ ?.let {
48
+ GradleClassPathResolver (
49
+ path = it,
50
+ includeKotlinDSL = file.endsWith(" .kts" ),
51
+ useCompileClasspath = options.useCompileClasspath,
52
+ )
53
+ }
44
54
}
45
55
}
46
56
@@ -73,13 +83,26 @@ private fun getGradleCommand(workspace: Path): Path {
73
83
}
74
84
}
75
85
76
- private fun readDependenciesViaGradleCLI (projectDirectory : Path , gradleScripts : List <String >, gradleTasks : List <String >): Set <Path > {
86
+ private fun readDependenciesViaGradleCLI (
87
+ projectDirectory : Path ,
88
+ gradleScripts : List <String >,
89
+ gradleTasks : List <String >,
90
+ useCompileClasspath : Boolean = true,
91
+ ): Set <Path > {
77
92
LOG .info(" Resolving dependencies for '{}' through Gradle's CLI using tasks {}..." , projectDirectory.fileName, gradleTasks)
78
93
79
94
val tmpScripts = gradleScripts.map { gradleScriptToTempFile(it, deleteOnExit = false ).toPath().toAbsolutePath() }
80
95
val gradle = getGradleCommand(projectDirectory)
81
96
82
- val command = listOf (gradle.toString()) + tmpScripts.flatMap { listOf (" -I" , it.toString()) } + gradleTasks + listOf (" --console=plain" )
97
+ val command = mutableListOf<String >().apply {
98
+ add(gradle.toString())
99
+ addAll(tmpScripts.flatMap { listOf (" -I" , it.toString()) })
100
+ addAll(gradleTasks)
101
+ add(" --console=plain" )
102
+
103
+ if (useCompileClasspath) add(" -PuseCompileClasspath=1" )
104
+ }.toList()
105
+
83
106
val dependencies = findGradleCLIDependencies(command, projectDirectory)
84
107
?.also { LOG .debug(" Classpath for task {}" , it) }
85
108
.orEmpty()
0 commit comments