@@ -10,15 +10,19 @@ import java.nio.file.Files
1010import java.nio.file.Path
1111import java.nio.file.Paths
1212
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 {
1418 override val resolverType: String = " Gradle"
1519 private val projectDirectory: Path get() = path.parent
1620
1721 override val classpath: Set <ClassPathEntry > get() {
1822 val scripts = listOf (" projectClassPathFinder.gradle" )
1923 val tasks = listOf (" kotlinLSPProjectDeps" )
2024
21- return readDependenciesViaGradleCLI(projectDirectory, scripts, tasks)
25+ return readDependenciesViaGradleCLI(projectDirectory, scripts, tasks, useCompileClasspath )
2226 .apply { if (isNotEmpty()) LOG .info(" Successfully resolved dependencies for '${projectDirectory.fileName} ' using Gradle" ) }
2327 .map { ClassPathEntry (it, null ) }.toSet()
2428 }
@@ -38,9 +42,15 @@ internal class GradleClassPathResolver(private val path: Path, private val inclu
3842
3943 companion object {
4044 /* * Create a Gradle resolver if a file is a pom. */
41- fun maybeCreate (file : Path ): GradleClassPathResolver ? =
45+ fun maybeCreate (file : Path , options : ResolverOptions ): GradleClassPathResolver ? =
4246 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+ }
4454 }
4555}
4656
@@ -73,13 +83,26 @@ private fun getGradleCommand(workspace: Path): Path {
7383 }
7484}
7585
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 > {
7792 LOG .info(" Resolving dependencies for '{}' through Gradle's CLI using tasks {}..." , projectDirectory.fileName, gradleTasks)
7893
7994 val tmpScripts = gradleScripts.map { gradleScriptToTempFile(it, deleteOnExit = false ).toPath().toAbsolutePath() }
8095 val gradle = getGradleCommand(projectDirectory)
8196
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+
83106 val dependencies = findGradleCLIDependencies(command, projectDirectory)
84107 ?.also { LOG .debug(" Classpath for task {}" , it) }
85108 .orEmpty()
0 commit comments