mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
If kapt{} detected, run javac before kotlinc.
This commit is contained in:
parent
e891025928
commit
5645d54e35
2 changed files with 27 additions and 2 deletions
|
@ -16,6 +16,7 @@ import com.beust.kobalt.misc.KobaltExecutors
|
|||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.warn
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -161,12 +162,32 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
throw KobaltException("Couldn't find any compiler for project ${project.name}")
|
||||
} else {
|
||||
val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted()
|
||||
allCompilers.forEach { compiler ->
|
||||
|
||||
/**
|
||||
* Swap the Java and Kotlin compilers from the list.
|
||||
*/
|
||||
fun swapJavaAndKotlin(allCompilers: List<ICompiler>): List<ICompiler> {
|
||||
val result = ArrayList(allCompilers)
|
||||
var ik = -1
|
||||
var ij = -1
|
||||
allCompilers.withIndex().forEach { wi ->
|
||||
if (wi.value.sourceSuffixes.contains("java")) ij = wi.index
|
||||
if (wi.value.sourceSuffixes.contains("kt")) ik = wi.index
|
||||
}
|
||||
Collections.swap(result, ik, ij)
|
||||
return result
|
||||
}
|
||||
|
||||
// If this project has a kapt{} directive, we want to run the Java compiler first
|
||||
val hasKapt = project.projectProperties.get("kaptConfig") != null
|
||||
var finalAllCompilers = if (hasKapt) swapJavaAndKotlin(allCompilers) else allCompilers
|
||||
finalAllCompilers.forEach { compiler ->
|
||||
val compilerResults = compilerUtils.invokeCompiler(project, context, compiler,
|
||||
sourceDirectories(project, context), isTest)
|
||||
results.addAll(compilerResults.successResults)
|
||||
if (failedResult == null) failedResult = compilerResults.failedResult
|
||||
}
|
||||
|
||||
return if (failedResult != null) failedResult!!
|
||||
else if (results.size > 0) results[0]
|
||||
else TaskResult(true)
|
||||
|
|
|
@ -47,6 +47,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "Apt"
|
||||
const val KAPT_CONFIG = "kaptConfig"
|
||||
}
|
||||
|
||||
override val name = PLUGIN_NAME
|
||||
|
@ -125,7 +126,10 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
|
||||
private val kaptConfigs: HashMap<String, KaptConfig> = hashMapOf()
|
||||
|
||||
fun addKaptConfig(project: Project, kapt: KaptConfig) = kaptConfigs.put(project.name, kapt)
|
||||
fun addKaptConfig(project: Project, kapt: KaptConfig) {
|
||||
project.projectProperties.put(KAPT_CONFIG, kapt)
|
||||
kaptConfigs.put(project.name, kapt)
|
||||
}
|
||||
}
|
||||
|
||||
class AptConfig(var outputDir: String = "generated/source/apt")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue