Provide default output JS file in Kotlin Gradle plugin
This commit is contained in:
+4
-4
@@ -66,12 +66,12 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNoOutputFileFails() {
|
fun testDefaultOutputFile() {
|
||||||
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
|
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertFailed()
|
assertSuccessful()
|
||||||
assertReportExists()
|
assertFileExists("build/classes/main/kotlin2JsNoOutputFileProject_main.js")
|
||||||
assertContains("compileKotlin2Js.kotlinOptions.outputFile should be specified.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -55,7 +55,8 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
|
|||||||
protected val sourceRootDir: String = "src/$sourceSetName/kotlin"
|
protected val sourceRootDir: String = "src/$sourceSetName/kotlin"
|
||||||
protected val kotlinSourceSet: KotlinSourceSet = createKotlinSourceSet()
|
protected val kotlinSourceSet: KotlinSourceSet = createKotlinSourceSet()
|
||||||
protected val kotlinTask: T = createKotlinCompileTask()
|
protected val kotlinTask: T = createKotlinCompileTask()
|
||||||
protected abstract val defaultKotlinDestinationDir: File
|
protected open val defaultKotlinDestinationDir: File
|
||||||
|
get() = sourceSet.output.classesDir
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
addKotlinDirSetToSources()
|
addKotlinDirSetToSources()
|
||||||
@@ -183,9 +184,6 @@ internal class Kotlin2JsSourceSetProcessor(
|
|||||||
taskDescription = "Compiles the kotlin sources in $sourceSet to JavaScript.",
|
taskDescription = "Compiles the kotlin sources in $sourceSet to JavaScript.",
|
||||||
compileTaskNameSuffix = "kotlin2Js"
|
compileTaskNameSuffix = "kotlin2Js"
|
||||||
) {
|
) {
|
||||||
override val defaultKotlinDestinationDir: File
|
|
||||||
get() = File(project.buildDir, "kotlin2js/$sourceSetName")
|
|
||||||
|
|
||||||
private val clean = project.tasks.findByName("clean")
|
private val clean = project.tasks.findByName("clean")
|
||||||
private val build = project.tasks.findByName("build")
|
private val build = project.tasks.findByName("build")
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -20,6 +20,7 @@ import org.codehaus.groovy.runtime.MethodClosure
|
|||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
|
import org.gradle.api.tasks.SourceSet
|
||||||
import org.gradle.api.tasks.SourceTask
|
import org.gradle.api.tasks.SourceTask
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.gradle.api.tasks.compile.AbstractCompile
|
import org.gradle.api.tasks.compile.AbstractCompile
|
||||||
@@ -299,6 +300,9 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
|||||||
|
|
||||||
var compilerJarFile: File? = null
|
var compilerJarFile: File? = null
|
||||||
|
|
||||||
|
private val defaultOutputFile: File
|
||||||
|
get() = File(destinationDir, "$moduleName.js")
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val outputFile: String?
|
val outputFile: String?
|
||||||
get() = kotlinOptions.outputFile
|
get() = kotlinOptions.outputFile
|
||||||
@@ -340,7 +344,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
|||||||
args.freeArgs = args.freeArgs + sourceRoots.kotlinSourceFiles.map { it.absolutePath }
|
args.freeArgs = args.freeArgs + sourceRoots.kotlinSourceFiles.map { it.absolutePath }
|
||||||
|
|
||||||
if (args.outputFile == null) {
|
if (args.outputFile == null) {
|
||||||
throw GradleException("$name.kotlinOptions.outputFile should be specified.")
|
args.outputFile = defaultOutputFile.canonicalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||||
|
|||||||
+1
@@ -33,6 +33,7 @@ internal open class KotlinTasksProvider {
|
|||||||
|
|
||||||
fun createKotlinJSTask(project: Project, name: String, sourceSetName: String): Kotlin2JsCompile =
|
fun createKotlinJSTask(project: Project, name: String, sourceSetName: String): Kotlin2JsCompile =
|
||||||
project.tasks.create(name, Kotlin2JsCompile::class.java).apply {
|
project.tasks.create(name, Kotlin2JsCompile::class.java).apply {
|
||||||
|
this.sourceSetName = sourceSetName
|
||||||
friendTaskName = taskToFriendTaskMapper[this]
|
friendTaskName = taskToFriendTaskMapper[this]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user