Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,9 @@ abstract class KspAATask @Inject constructor(
cfg.moduleName.value(moduleName)
val kotlinOutputDir = KspGradleSubplugin.getKspKotlinOutputDir(project, sourceSetName, target)
val javaOutputDir = KspGradleSubplugin.getKspJavaOutputDir(project, sourceSetName, target)
val filteredTasks =
kspExtension.excludedSources.buildDependencies.getDependencies(null).map { it.name }
kotlinCompilation.allKotlinSourceSetsObservable.forAll { sourceSet ->
val filtered = sourceSet.kotlin.srcDirs.filter {
!kotlinOutputDir.isParentOf(it) && !javaOutputDir.isParentOf(it) &&
it !in kspExtension.excludedSources
}.map {
// @SkipWhenEmpty doesn't work well with File.
project.objects.fileTree().from(it)
}
cfg.sourceRoots.from(filtered)
cfg.javaSourceRoots.from(filtered)
kspAATask.dependsOn(
sourceSet.kotlin.nonSelfDeps(kspTaskName).filter { it.name !in filteredTasks }
)
cfg.sourceRoots.from(sourceSet.kotlin.sourceDirectories)
cfg.javaSourceRoots.from(sourceSet.kotlin.sourceDirectories)
}
if (kotlinCompilation is KotlinCommonCompilation) {
cfg.commonSourceRoots.from(kotlinCompilation.defaultSourceSet.kotlin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ abstract class KspExtension @Inject constructor(project: Project) {

// Specify sources that should be excluded from KSP.
// If you have a task that generates sources, you can call `ksp.excludedSources.from(task)`.
// TODO - Deprecate and then remove this DSL?
abstract val excludedSources: ConfigurableFileCollection

open val arguments: Map<String, String> get() = apOptions.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
Expand Down Expand Up @@ -360,16 +359,8 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
)
}
} else {
val filteredTasks =
kspExtension.excludedSources.buildDependencies.getDependencies(null).map { it.name }
kotlinCompilation.allKotlinSourceSetsObservable.forAll { sourceSet ->
kspTask.setSource(
sourceSet.kotlin.srcDirs.filter {
!kotlinOutputDir.isParentOf(it) && !javaOutputDir.isParentOf(it) &&
it !in kspExtension.excludedSources
}
)
kspTask.dependsOn(sourceSet.kotlin.nonSelfDeps(kspTaskName).filter { it.name !in filteredTasks })
kspTask.setSource(sourceSet.kotlin.sourceDirectories)
}
}

Expand Down Expand Up @@ -603,13 +594,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
project.files(kotlinOutputDir).builtBy(kspTaskProvider),
project.files(javaOutputDir).builtBy(kspTaskProvider),
)
if (kotlinCompilation is KotlinCommonCompilation) {
// Do not add generated sources to common source sets.
// They will be observed by downstreams and violate current build scheme.
kotlinCompileProvider.configure { it.source(*generatedSources) }
} else {
kotlinCompilation.defaultSourceSet.kotlin.srcDirs(*generatedSources)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for adding generated sources to kotlinCompilation.defaultSourceSet and all corresponding workarounds is IDE support, which is not covered in KSP's tests unfortunately. Without this, users would add the output folder of KSP to the source set and suffer from the same (if not more) issue.

I got a couple of alternatives but they are apparently beyond the scope of this PR.

  1. Work with KGP / JetBrains to get an API for registering generated sources, like those provided by AGP.
  2. Implement IDE plugins for KSP.

Are there easier solutions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there easier solutions?

I can't think of a way to make it work with existing APIs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
kotlinCompileProvider.configure { it.source(*generatedSources) }

kotlinCompileProvider.configure { kotlinCompile ->
when (kotlinCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ class AndroidIT(useKSP2: Boolean) {

// Disabling configuration cache. See https://github.com/google/ksp/issues/299 for details
gradleRunner.withArguments(
"clean", "build", "minifyReleaseWithR8", "--configuration-cache-problems=warn", "--info", "--stacktrace"
"clean",
"build",
"minifyReleaseWithR8",
"--info",
"--stacktrace",
"-Dorg.gradle.unsafe.isolated-projects=true"
).build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:build")?.outcome)
val mergedConfiguration = File(project.root, "workload/build/outputs/mapping/release/configuration.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,3 @@ buildscript {
google()
}
}

allprojects {
val testRepo: String by project
repositories {
maven(testRepo)
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
google()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
maven(testRepo)
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
google()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repositories {
maven(testRepo)
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
google()
}

dependencies {
Expand Down
Loading