org.jetbrains.kotlin.gradle.targets.jvm.KotlinWithJavaCompilation.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("PackageDirectoryMismatch", "UNCHECKED_CAST") // Old package for compatibility
package org.jetbrains.kotlin.gradle.plugin.mpp
import org.gradle.api.Action
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.compile.JavaCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.utils.named
import javax.inject.Inject
open class KotlinWithJavaCompilation @Inject internal constructor(
compilation: KotlinCompilationImpl,
val javaSourceSet: SourceSet,
) : AbstractKotlinCompilationToRunnableFiles(compilation),
KotlinCompilationWithResources {
@Suppress("UNCHECKED_CAST")
override val compilerOptions: HasCompilerOptions =
compilation.compilerOptions as HasCompilerOptions
internal fun compilerOptions(configure: CO.() -> Unit) {
compilerOptions.configure(configure)
}
internal fun compilerOptions(configure: Action) {
configure.execute(compilerOptions.options)
}
val compileJavaTaskProvider: TaskProvider
get() = target.project.tasks.withType(JavaCompile::class.java).named(javaSourceSet.compileJavaTaskName)
override val processResourcesTaskName: String
get() = compilation.processResourcesTaskName ?: error("Missing 'processResourcesTaskName'")
fun source(javaSourceSet: SourceSet) {
with(target.project) {
afterEvaluate {
tasks.named>(compileKotlinTaskName).configure {
it.setSource(javaSourceSet.java)
}
}
}
}
}