inject Kotlin classes to javac classpath carefully
This commit is contained in:
+10
-7
@@ -62,20 +62,23 @@ open class KotlinPlugin: Plugin<Project> {
|
||||
val kotlinTask: KotlinCompile = project.getTasks().add(kotlinTaskName, javaClass<KotlinCompile>())!!
|
||||
|
||||
javaBasePlugin.configureForSourceSet(sourceSet, kotlinTask)
|
||||
// store kotlin classes in separate directory. They will serve as class-path to java compiler
|
||||
val kotlinOutputDir = File(project.getBuildDir(), "kotlin-classes/${sourceSetName}")
|
||||
// builtBy allows to correctly run kotlinTask as a transitive dependency on anything,
|
||||
// that wants to use sourceSet output (e.g., 'jar' task
|
||||
sourceSet.getOutput()?.dir(mapOf(Pair("builtBy", kotlinTask)), kotlinOutputDir)
|
||||
kotlinTask.setDestinationDir(kotlinOutputDir);
|
||||
|
||||
kotlinTask.setDescription("Compiles the $sourceSet.kotlin.")
|
||||
kotlinTask.source(kotlinDirSet)
|
||||
|
||||
val javaTask = project.getTasks().findByName(sourceSet.getCompileJavaTaskName()) as AbstractCompile?
|
||||
javaTask?.dependsOn(kotlinTaskName)
|
||||
|
||||
val sourceSetCompileConfigurationName = if (sourceSetName == SourceSet.MAIN_SOURCE_SET_NAME) {
|
||||
"compile"
|
||||
} else {
|
||||
"${sourceSetName}Compile"
|
||||
if (javaTask != null) {
|
||||
javaTask.dependsOn(kotlinTaskName)
|
||||
val javacClassPath = javaTask.getClasspath() + project.files(kotlinTask.getDestinationDir());
|
||||
javaTask.setClasspath(javacClassPath)
|
||||
}
|
||||
|
||||
project.getDependencies()?.add(sourceSetCompileConfigurationName, project.files(kotlinTask.getDestinationDir()))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+26
-1
@@ -38,7 +38,6 @@ class BasicKotlinGradleIT {
|
||||
|
||||
val builder = ProcessBuilder(cmd)
|
||||
builder.directory(projectDir)
|
||||
|
||||
builder.redirectErrorStream(true)
|
||||
val process = builder.start()
|
||||
|
||||
@@ -59,6 +58,32 @@ class BasicKotlinGradleIT {
|
||||
assertTrue(buildOutput.contains(":compileKotlin"), "Should contain ':compileKotlin'")
|
||||
assertTrue(buildOutput.contains(":compileTestKotlin"), "Should contain ':compileTestKotlin'")
|
||||
assertTrue(buildOutput.contains(":compileDeployKotlin"), "Should contain ':compileDeployKotlin'")
|
||||
|
||||
// Run the build second time, assert everything is up-to-date
|
||||
|
||||
val up2dateBuilder = ProcessBuilder(cmd)
|
||||
up2dateBuilder.directory(projectDir)
|
||||
up2dateBuilder.redirectErrorStream(true)
|
||||
val up2dateProcess = up2dateBuilder.start()
|
||||
|
||||
val up2dateProcessScanner = Scanner(up2dateProcess.getInputStream()!!)
|
||||
val up2dateText = StringBuilder()
|
||||
while (up2dateProcessScanner.hasNextLine()) {
|
||||
up2dateText append up2dateProcessScanner.nextLine()
|
||||
up2dateText append "\n"
|
||||
}
|
||||
up2dateProcessScanner.close()
|
||||
|
||||
val up2dateResult = up2dateProcess.waitFor()
|
||||
val up2dateBuildOutput = up2dateText.toString()
|
||||
|
||||
println(up2dateBuildOutput)
|
||||
|
||||
assertEquals(up2dateResult, 0)
|
||||
assertTrue(up2dateBuildOutput.contains(":compileKotlin UP-TO-DATE"), "Should contain ':compileKotlin UP-TO-DATE'")
|
||||
assertTrue(up2dateBuildOutput.contains(":compileTestKotlin UP-TO-DATE"), "Should contain ':compileTestKotlin UP-TO-DATE'")
|
||||
assertTrue(up2dateBuildOutput.contains(":compileDeployKotlin UP-TO-DATE"), "Should contain ':compileDeployKotlin UP-TO-DATE'")
|
||||
assertTrue(up2dateBuildOutput.contains(":compileJava UP-TO-DATE"), "Should contain ':compileJava UP-TO-DATE'")
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user