Skip to content

Commit f68437a

Browse files
ting-yuanKSP Auto Pick
authored and
KSP Auto Pick
committed
KSP2: better support of compilation avoidance
by setting up the incremental properties on classpathStructure instead of libraries. (cherry picked from commit 675d392)
1 parent e764de7 commit f68437a

File tree

1 file changed

+24
-7
lines changed
  • gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle

1 file changed

+24
-7
lines changed

gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspAATask.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.gradle.process.CommandLineArgumentProvider
3434
import org.gradle.work.ChangeType
3535
import org.gradle.work.Incremental
3636
import org.gradle.work.InputChanges
37+
import org.gradle.work.NormalizeLineEndings
3738
import org.gradle.workers.WorkAction
3839
import org.gradle.workers.WorkParameters
3940
import org.gradle.workers.WorkerExecutor
@@ -97,7 +98,7 @@ abstract class KspAATask @Inject constructor(
9798
kspConfig.sourceRoots,
9899
kspConfig.javaSourceRoots,
99100
kspConfig.commonSourceRoots,
100-
kspConfig.libraries
101+
kspConfig.classpathStructure,
101102
),
102103
kspConfig.cachesDir.asFile.get(),
103104
kspConfig.classpathStructure,
@@ -107,7 +108,7 @@ abstract class KspAATask @Inject constructor(
107108
} else {
108109
if (
109110
!inputChanges.isIncremental ||
110-
inputChanges.getFileChanges(kspConfig.libraries).iterator().hasNext()
111+
inputChanges.getFileChanges(kspConfig.nonJvmLibraries).iterator().hasNext()
111112
)
112113
kspConfig.cachesDir.get().asFile.deleteRecursively()
113114
emptyList()
@@ -264,8 +265,6 @@ abstract class KspAATask @Inject constructor(
264265
.orElse(false)
265266
)
266267

267-
cfg.classpathStructure.from(getClassStructureFiles(project, cfg.libraries))
268-
269268
if (compilerOptions is KotlinJvmCompilerOptions) {
270269
// TODO: set proper jdk home
271270
cfg.jdkHome.value(File(System.getProperty("java.home")))
@@ -284,6 +283,10 @@ abstract class KspAATask @Inject constructor(
284283
cfg.jvmDefaultMode.value(jvmDefaultMode)
285284

286285
cfg.jvmTarget.value(compilerOptions.jvmTarget.map { it.target })
286+
287+
cfg.classpathStructure.from(getClassStructureFiles(project, cfg.libraries))
288+
} else {
289+
cfg.nonJvmLibraries.from(cfg.libraries)
287290
}
288291

289292
cfg.platformType.value(kotlinCompilation.platformType)
@@ -332,8 +335,9 @@ abstract class KspGradleConfig @Inject constructor() {
332335
@get:PathSensitive(PathSensitivity.RELATIVE)
333336
abstract val javaSourceRoots: ConfigurableFileCollection
334337

335-
@get:Incremental
336-
@get:Classpath
338+
// Marked as Internal for compilation avoidance.
339+
// classpathStructure has the needed incremental properties.
340+
@get:Internal
337341
abstract val libraries: ConfigurableFileCollection
338342

339343
@get:Internal
@@ -397,9 +401,22 @@ abstract class KspGradleConfig @Inject constructor() {
397401
@get:Input
398402
abstract val incrementalLog: Property<Boolean>
399403

400-
@get:Internal
404+
@get:PathSensitive(PathSensitivity.NONE)
405+
@get:Incremental
406+
@get:IgnoreEmptyDirectories
407+
@get:NormalizeLineEndings
408+
@get:Optional
409+
@get:InputFiles
401410
abstract val classpathStructure: ConfigurableFileCollection
402411

412+
@get:PathSensitive(PathSensitivity.RELATIVE)
413+
@get:Incremental
414+
@get:IgnoreEmptyDirectories
415+
@get:NormalizeLineEndings
416+
@get:Optional
417+
@get:InputFiles
418+
abstract val nonJvmLibraries: ConfigurableFileCollection
419+
403420
@get:Input
404421
abstract val platformType: Property<KotlinPlatformType>
405422

0 commit comments

Comments
 (0)