Implementing workaround for not being able to set java task classpath statically and therefore making it unable to detect changes in kotlin classes
KT-8487
This commit is contained in:
committed by
Alexey Tsvetkov
parent
df63fc30f6
commit
ddf3ca276b
+7
@@ -62,6 +62,8 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
|
|||||||
var kotlinOptions: T = createBlankArgs()
|
var kotlinOptions: T = createBlankArgs()
|
||||||
var kotlinDestinationDir: File? = destinationDir
|
var kotlinDestinationDir: File? = destinationDir
|
||||||
var compilerCalled: Boolean = false
|
var compilerCalled: Boolean = false
|
||||||
|
// TODO: consider more reliable approach (see usage)
|
||||||
|
var anyClassesCompiled: Boolean = false
|
||||||
|
|
||||||
private val loggerInstance = Logging.getLogger(this.javaClass)
|
private val loggerInstance = Logging.getLogger(this.javaClass)
|
||||||
override fun getLogger() = loggerInstance
|
override fun getLogger() = loggerInstance
|
||||||
@@ -361,6 +363,8 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
fun outputRelativePath(f: File) = f.toRelativeString(outputDir)
|
fun outputRelativePath(f: File) = f.toRelativeString(outputDir)
|
||||||
|
|
||||||
|
|
||||||
|
anyClassesCompiled = false
|
||||||
|
|
||||||
// TODO: decide what to do if no files are considered dirty - rebuild or skip the module
|
// TODO: decide what to do if no files are considered dirty - rebuild or skip the module
|
||||||
var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile()
|
var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile()
|
||||||
|
|
||||||
@@ -450,6 +454,9 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
lookupStorage.flush(false)
|
lookupStorage.flush(false)
|
||||||
lookupStorage.close()
|
lookupStorage.close()
|
||||||
caches.values.forEach { it.flush(false); it.close() }
|
caches.values.forEach { it.flush(false); it.close() }
|
||||||
|
if (allGeneratedFiles.isNotEmpty()) {
|
||||||
|
anyClassesCompiled = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class CompileChangedResults(val exitCode: ExitCode, val generatedFiles: List<GeneratedFile<TargetId>>)
|
private data class CompileChangedResults(val exitCode: ExitCode, val generatedFiles: List<GeneratedFile<TargetId>>)
|
||||||
|
|||||||
+14
@@ -133,6 +133,20 @@ class Kotlin2JvmSourceSetProcessor(
|
|||||||
val javaTask = project.tasks.findByName(sourceSet.compileJavaTaskName) as AbstractCompile?
|
val javaTask = project.tasks.findByName(sourceSet.compileJavaTaskName) as AbstractCompile?
|
||||||
|
|
||||||
if (javaTask != null) {
|
if (javaTask != null) {
|
||||||
|
// Since we cannot update classpath statically, java not able to detect changes in the classpath after kotlin compiler.
|
||||||
|
// Therefore this (probably inefficient since java cannot decide "uptodateness" by the list of changed class files, but told
|
||||||
|
// explicitly being out of date whenever any kotlin files are compiled
|
||||||
|
kotlinTask.property("anyClassesCompiled")?.let {
|
||||||
|
kotlinTask.setProperty("anyClassesCompiled", false)
|
||||||
|
javaTask.outputs.upToDateWhen { task ->
|
||||||
|
val kotlinClassesCompiled = kotlinTask.property("anyClassesCompiled") as? Boolean ?: false
|
||||||
|
if (kotlinClassesCompiled) {
|
||||||
|
logger.info("Marking $task out of date, because kotlin classes are changed")
|
||||||
|
}
|
||||||
|
!kotlinClassesCompiled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
javaTask.dependsOn(kotlinTaskName)
|
javaTask.dependsOn(kotlinTaskName)
|
||||||
javaTask.doFirst {
|
javaTask.doFirst {
|
||||||
javaTask.classpath += project.files(kotlinDestinationDir)
|
javaTask.classpath += project.files(kotlinDestinationDir)
|
||||||
|
|||||||
Reference in New Issue
Block a user