Introduce single-project extensions with static types for Kotlin target

This commit is contained in:
Sergey Igushkin
2019-02-28 16:40:29 +03:00
parent b3eef05e6e
commit 4e711f9a0c
9 changed files with 164 additions and 14 deletions
@@ -891,4 +891,34 @@ class KotlinGradleIT : BaseGradleIT() {
assertNotContains(MULTIPLE_KOTLIN_PLUGINS_SPECIFIC_PROJECTS_WARNING)
}
}
@Test
fun testNewModelInOldJvmPlugin() = with(Project("new-model-in-old-plugin", GradleVersionRequired.AtLeast("4.10.2"))) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
build("publish", "check", "runBenchmark") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileTestKotlin", ":compileBenchmarkKotlin", ":test", ":runBenchmark")
// Find the benchmark output:
assertContains("f ran at the speed of light")
val moduleDir = "build/repo/com/example/new-model/1.0/"
val publishedJar = fileInWorkingDir(moduleDir + "new-model-1.0.jar")
ZipFile(publishedJar).use { zip ->
val entries = zip.entries().asSequence().map { it.name }
assertTrue { "com/example/A.class" in entries }
}
val publishedPom = fileInWorkingDir(moduleDir + "new-model-1.0.pom")
val kotlinVersion = defaultBuildOptions().kotlinVersion
val pomText = publishedPom.readText().replace(Regex("\\s+"), "")
assertTrue { "kotlin-gradle-plugin-api</artifactId><version>$kotlinVersion</version><scope>compile</scope>" in pomText }
assertTrue { "kotlin-stdlib-jdk8</artifactId><version>$kotlinVersion</version><scope>runtime</scope>" in pomText }
assertFileExists(moduleDir + "new-model-1.0-sources.jar")
}
}
}
@@ -0,0 +1,60 @@
plugins {
kotlin("jvm").version("<pluginMarkerVersion>")
`maven-publish`
}
group = "com.example"
version = "1.0"
repositories {
mavenLocal()
jcenter()
}
kotlin.target.compilations {
all {
kotlinOptions {
allWarningsAsErrors = true
jvmTarget = "1.8"
}
}
val main by getting {
defaultSourceSet.dependencies {
api(kotlin("gradle-plugin-api"))
implementation(kotlin("stdlib-jdk8"))
}
}
val test by getting {
defaultSourceSet.dependencies {
implementation(kotlin("test-junit"))
}
}
val benchmark by creating {
defaultSourceSet.dependencies {
implementation(main.compileDependencyFiles + main.output.allOutputs)
runtimeOnly(main.runtimeDependencyFiles)
implementation(kotlin("reflect"))
}
}
}
val runBenchmark by tasks.registering(JavaExec::class) {
classpath = kotlin.target.compilations["benchmark"].run { runtimeDependencyFiles + output.allOutputs }
main = "com.example.ABenchmarkKt"
}
publishing {
publications {
create("default", MavenPublication::class) {
from(kotlin.target.components.single())
artifact(tasks.getByName("kotlinSourcesJar"))
}
}
repositories {
maven("${buildDir}/repo")
}
}
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
rootProject.name = "new-model"
@@ -0,0 +1,8 @@
package com.example
fun main() {
val a = A()
val f = a::f
f()
println("${a::f.name} ran at the speed of light")
}
@@ -0,0 +1,5 @@
package com.example
class A {
fun f(): String = "hello".also(::println)
}
@@ -0,0 +1,11 @@
package com.example
import kotlin.test.*
class ATest {
@Test
fun testF() {
val f = A().f()
assertEquals("hello", f)
}
}