Gradle plugin: do not store generated folder for android into sourceSets, because they are reused for different buildTypes and flavors
#KT-8202 Fixed #KT-9715 Fixed
This commit is contained in:
+22
-13
@@ -10,8 +10,8 @@ import org.gradle.api.GradleException
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension
|
||||
import org.gradle.api.tasks.SourceTask
|
||||
import java.util.HashSet
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
@@ -26,13 +26,8 @@ import org.jetbrains.kotlin.cli.js.K2JSCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.utils.LibraryUtils
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.jetbrains.org.objectweb.asm.ClassWriter
|
||||
import java.io.IOException
|
||||
import java.lang.ref.WeakReference
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
val DEFAULT_ANNOTATIONS = "org.jebrains.kotlin.gradle.defaultAnnotations"
|
||||
|
||||
@@ -102,7 +97,8 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
override val compiler = K2JVMCompiler()
|
||||
override fun createBlankArgs(): K2JVMCompilerArguments = K2JVMCompilerArguments()
|
||||
|
||||
val srcDirsSources = HashSet<SourceDirectorySet>()
|
||||
// Should be SourceDirectorySet or File
|
||||
val srcDirsSources = HashSet<Any>()
|
||||
|
||||
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
|
||||
// show kotlin compiler where to look for java source files
|
||||
@@ -178,30 +174,43 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
|
||||
}
|
||||
}
|
||||
|
||||
// override setSource to track source directory sets
|
||||
// override setSource to track source directory sets and files (for generated android folders)
|
||||
override fun setSource(source: Any?) {
|
||||
srcDirsSources.clear()
|
||||
if (source is SourceDirectorySet) {
|
||||
srcDirsSources.add(source)
|
||||
}
|
||||
else if (source is File) {
|
||||
srcDirsSources.add(source)
|
||||
}
|
||||
super.setSource(source)
|
||||
}
|
||||
|
||||
// override source to track source directory sets
|
||||
// override source to track source directory sets and files (for generated android folders)
|
||||
override fun source(vararg sources: Any?): SourceTask? {
|
||||
for (source in sources) {
|
||||
if (source is SourceDirectorySet) {
|
||||
srcDirsSources.add(source)
|
||||
}
|
||||
else if (source is File) {
|
||||
srcDirsSources.add(source)
|
||||
}
|
||||
}
|
||||
return super.source(sources)
|
||||
}
|
||||
|
||||
fun findSrcDirRoot(file: File): File? {
|
||||
for (source in srcDirsSources) {
|
||||
for (root in source.getSrcDirs()) {
|
||||
if (FileUtil.isAncestor(root, file, false)) {
|
||||
return root
|
||||
if (source is SourceDirectorySet) {
|
||||
for (root in source.getSrcDirs()) {
|
||||
if (FileUtil.isAncestor(root, file, false)) {
|
||||
return root
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (source is File) {
|
||||
if (FileUtil.isAncestor(source, file, false)) {
|
||||
return source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-12
@@ -374,18 +374,6 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
||||
}
|
||||
}
|
||||
|
||||
fun configureDefaultSourceSet() {
|
||||
val defaultSourceSet = variantData.getVariantConfiguration().getDefaultSourceSet()
|
||||
val kotlinSourceDirectorySet = getExtension<KotlinSourceSet>(defaultSourceSet, "kotlin").getKotlin()
|
||||
// getJavaSources should return the Java sources used for compilation
|
||||
// We want to collect only generated files, like R-class output dir
|
||||
// Actual java sources will be collected later
|
||||
val additionalSourceFiles = variantData.getJavaSources().filterIsInstance(javaClass<File>())
|
||||
kotlinSourceDirectorySet.addSourceDirectories(additionalSourceFiles)
|
||||
}
|
||||
|
||||
configureDefaultSourceSet()
|
||||
|
||||
val aptFiles = arrayListOf<File>()
|
||||
|
||||
// getSortedSourceProviders should return only actual java sources, generated sources should be collected earlier
|
||||
@@ -405,6 +393,15 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
||||
}
|
||||
}
|
||||
|
||||
// getJavaSources should return the Java sources used for compilation
|
||||
// We want to collect only generated files, like R-class output dir
|
||||
// Actual java sources will be collected later
|
||||
val additionalSourceFiles = variantData.getJavaSources().filterIsInstance(javaClass<File>())
|
||||
for (file in additionalSourceFiles) {
|
||||
kotlinTask.source(file)
|
||||
logger.kotlinDebug("Source directory with generated files ${file.getAbsolutePath()} was added to kotlin source for $kotlinTaskName")
|
||||
}
|
||||
|
||||
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
||||
|
||||
kotlinTask doFirst {
|
||||
|
||||
Reference in New Issue
Block a user