Introduce new Gradle plugin org.jetbrains.kotlin.js

This is the Gradle plugin that does not rely on the
Java model and uses the same Kotlin model
(target – compilation – source set) as MPP does.

Also add JS DCE support for this plugin.

Issue #KT-5756 Fixed
Issue #KT-13256 Fixed
Issue #KT-16355 Fixed
Issue #KT-20156 Fixed
Issue #KT-29284 Fixed
This commit is contained in:
Sergey Igushkin
2019-03-12 18:24:23 +03:00
parent 03b74343c8
commit 91ce7ef5ca
18 changed files with 230 additions and 57 deletions
@@ -349,4 +349,36 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
assertNotContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
}
}
@Test
fun testNewKotlinJsPlugin() = with(Project("kotlin-js-plugin-project", GradleVersionRequired.AtLeast("4.10.2"))) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl)
build("publish", "runDceKotlin", "test", "runDceBenchmarkKotlin") {
assertSuccessful()
assertTasksExecuted(
":compileKotlin", ":compileTestKotlin", ":compileBenchmarkKotlin",
":runDceKotlin", ":runDceBenchmarkKotlin"
)
val moduleDir = "build/repo/com/example/kotlin-js-plugin/1.0/"
val publishedJar = fileInWorkingDir(moduleDir + "kotlin-js-plugin-1.0.jar")
ZipFile(publishedJar).use { zip ->
val entries = zip.entries().asSequence().map { it.name }
assertTrue { "kotlin-js-plugin.js" in entries }
}
val publishedPom = fileInWorkingDir(moduleDir + "kotlin-js-plugin-1.0.pom")
val kotlinVersion = defaultBuildOptions().kotlinVersion
val pomText = publishedPom.readText().replace(Regex("\\s+"), "")
assertTrue { "kotlinx-html-js</artifactId><version>0.6.10</version><scope>compile</scope>" in pomText }
assertTrue { "kotlin-stdlib-js</artifactId><version>$kotlinVersion</version><scope>runtime</scope>" in pomText }
assertFileExists(moduleDir + "kotlin-js-plugin-1.0-sources.jar")
}
}
}
@@ -0,0 +1,47 @@
plugins {
kotlin("js").version("<pluginMarkerVersion>")
id("kotlin-dce-js")
`maven-publish`
}
group = "com.example"
version = "1.0"
repositories {
mavenLocal()
jcenter()
}
kotlin.sourceSets {
main {
dependencies {
api("org.jetbrains.kotlinx:kotlinx-html-js:0.6.10")
implementation(kotlin("stdlib-js"))
}
}
test {
dependencies {
implementation(kotlin("test-js"))
}
}
}
kotlin.target.compilations.create("benchmark") {
defaultSourceSet.dependencies {
val main by kotlin.target.compilations
implementation(main.compileDependencyFiles + main.output.classesDirs)
runtimeOnly(main.runtimeDependencyFiles)
}
}
publishing {
publications {
create("default", MavenPublication::class.java) {
from(kotlin.target.components.single())
artifact(tasks.getByName("kotlinSourcesJar"))
}
}
repositories {
maven("$buildDir/repo")
}
}
@@ -0,0 +1,15 @@
pluginManagement {
resolutionStrategy {
eachPlugin{
when (requested.id.id) {
"kotlin-dce-js" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:<pluginMarkerVersion>")
}
}
}
repositories {
mavenLocal()
gradlePluginPortal()
}
}
rootProject.name = "kotlin-js-plugin"
@@ -0,0 +1,9 @@
package com.example
class MainBenchmark {
fun runBenchmark() {
main()
hello()
console.log("ran at the speed of light")
}
}
@@ -0,0 +1,15 @@
package com.example
import kotlinx.html.dom.create
import kotlinx.html.js.div
import kotlinx.html.p
import kotlin.browser.document
fun hello() = "hello"
fun main() {
document.create.div {
p { hello() }
}
console.log(hello())
}
@@ -0,0 +1,11 @@
package com.example
import kotlin.test.Test
import kotlin.test.assertEquals
class MainTest {
@Test
fun testHello() {
assertEquals("hello", hello())
}
}