Fix kaptGenerateStubs doesn't ignore empty Android source directories
^KT-48617 Fixed
This commit is contained in:
+28
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import kotlin.io.path.createDirectory
|
||||
|
||||
@DisplayName("Build cache relocation")
|
||||
@SimpleGradlePluginTests
|
||||
@@ -166,6 +167,33 @@ class BuildCacheRelocationIT : KGPBaseTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@DisplayName("KT-48617: Kapt ignores empty directories from Android variant")
|
||||
@GradleTestVersions(minVersion = TestVersions.Gradle.G_6_8)
|
||||
@GradleTest
|
||||
fun kaptIgnoreEmptyAndroidVariant(gradleVersion: GradleVersion) {
|
||||
val (firstProject, secondProject) = prepareTestProjects(
|
||||
"kapt2/android-dagger",
|
||||
gradleVersion,
|
||||
defaultBuildOptions.copy(androidVersion = TestVersions.AGP.AGP_42)
|
||||
) {
|
||||
it.subProject("app").buildGradle.append("\nkapt.useBuildCache = true")
|
||||
}
|
||||
|
||||
firstProject.subProject("app").javaSourcesDir()
|
||||
.resolve("com/example/dagger/kotlin/fakeempty").createDirectory()
|
||||
|
||||
checkBuildCacheRelocation(
|
||||
firstProject,
|
||||
secondProject,
|
||||
listOf("assembleDebug"),
|
||||
listOf("Debug").flatMap { buildType ->
|
||||
listOf("kapt", "kaptGenerateStubs", "compile").map { kotlinTask ->
|
||||
":app:$kotlinTask${buildType}Kotlin"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@DisplayName("with native project")
|
||||
@GradleTest
|
||||
@DisabledOnOs(OS.WINDOWS, disabledReason = "remove after fix of KT-48283")
|
||||
|
||||
+2
-2
@@ -324,14 +324,14 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
)
|
||||
|
||||
if (androidVariantData != null) {
|
||||
kaptGenerateStubsTask.inputs.files(
|
||||
kaptGenerateStubsTask.additionalSources.from(
|
||||
Callable {
|
||||
// Avoid circular dependency: the stubs task need the Java sources, but the Java sources generated by Kapt should be
|
||||
// excluded, as the Kapt tasks depend on the stubs ones, and having them in the input would lead to a cycle
|
||||
val kaptJavaOutput = kaptTaskProvider.get().destinationDir
|
||||
androidVariantData.getSourceFolders(SourceKind.JAVA).filter { it.dir != kaptJavaOutput }
|
||||
}
|
||||
).withPathSensitivity(PathSensitivity.RELATIVE)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -108,6 +108,15 @@ abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
@get:Input
|
||||
abstract val verbose: Property<Boolean>
|
||||
|
||||
/**
|
||||
* Changes in this additional sources will trigger stubs regeneration,
|
||||
* but the sources themselves will not be used to find kapt annotations and generate stubs.
|
||||
*/
|
||||
@get:InputFiles
|
||||
@get:IgnoreEmptyDirectories
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract val additionalSources: ConfigurableFileCollection
|
||||
|
||||
override fun source(vararg sources: Any): SourceTask {
|
||||
return super.source(sourceRootsContainer.add(sources))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user