Skip to content

Commit 964cd92

Browse files
turanskyqwwdfsad
authored andcommitted
Transition to the Gradle kts
Non-deprecated 'jmhJar' configuration (#2032) (+9 squashed commits) Squashed commits: [8d07d36] Use new Kotlin/JS plugin (#1983) * Use new Kotlin/JS plugin * Support legacy DCE mode for 1.4-M2 [d224640] Add Dokka configuration method [56e1c9b] Dokka plugin in 'buildSrc' [dfdd202] Remove unused repositories [4cf1d02] Kotlin DSL - 'javafx' [d8f7d50] Avoid task name duplication [f06a56b] Avoid task name duplication [a09df3d] Separate 'UnpackAar' action [fd5bf6b] Separate 'RunR8' task
1 parent 63156a8 commit 964cd92

File tree

19 files changed

+226
-195
lines changed

19 files changed

+226
-195
lines changed

benchmarks/build.gradle.kts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("UnstableApiUsage")
6+
57
import me.champeau.gradle.*
68
import org.jetbrains.kotlin.gradle.tasks.*
79

@@ -33,7 +35,7 @@ tasks.named<KotlinCompile>("compileJmhKotlin") {
3335
* Due to a bug in the inliner it sometimes does not remove inlined symbols (that are later renamed) from unused code paths,
3436
* and it breaks JMH that tries to post-process these symbols and fails because they are renamed.
3537
*/
36-
val removeRedundantFiles = tasks.register<Delete>("removeRedundantFiles") {
38+
val removeRedundantFiles by tasks.registering(Delete::class) {
3739
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class")
3840
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$nBlanks\$1\$\$special\$\$inlined\$map\$1\$1.class")
3941
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$score2\$1\$\$special\$\$inlined\$map\$1\$1.class")
@@ -71,10 +73,10 @@ extensions.configure<JMHPluginExtension>("jmh") {
7173
}
7274

7375
tasks.named<Jar>("jmhJar") {
74-
baseName = "benchmarks"
75-
classifier = null
76-
version = null
77-
destinationDir = file("$rootDir")
76+
archiveBaseName by "benchmarks"
77+
archiveClassifier by null
78+
archiveVersion by null
79+
destinationDirectory.file("$rootDir")
7880
}
7981

8082
dependencies {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }
252252
}
253253

254254
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
255-
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
255+
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != 'example-frontend-js' && it.name != coreModule }) {
256256
sourceSets {
257257
main.kotlin.srcDirs = ['src']
258258
test.kotlin.srcDirs = ['test']

buildSrc/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import java.util.*
2+
13
plugins {
24
`kotlin-dsl`
35
}
46

57
repositories {
68
gradlePluginPortal()
9+
maven("https://kotlin.bintray.com/kotlin-eap")
10+
maven("https://kotlin.bintray.com/kotlin-dev")
711
}
812

913
kotlinDslPluginOptions {
1014
experimentalWarning.set(false)
1115
}
16+
17+
val props = Properties().apply {
18+
file("../gradle.properties").inputStream().use { load(it) }
19+
}
20+
21+
fun version(target: String): String =
22+
props.getProperty("${target}_version")
23+
24+
dependencies {
25+
implementation(kotlin("gradle-plugin", version("kotlin")))
26+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${version("dokka")}")
27+
}

buildSrc/src/main/kotlin/Dokka.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import org.gradle.api.Project
6+
import org.gradle.kotlin.dsl.delegateClosureOf
7+
import org.gradle.kotlin.dsl.withType
8+
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder
9+
import org.jetbrains.dokka.gradle.DokkaTask
10+
import java.io.File
11+
import java.net.URL
12+
13+
fun Project.externalDocumentationLink(
14+
url: String,
15+
packageList: File = projectDir.resolve("package.list")
16+
) {
17+
tasks.withType<DokkaTask>().configureEach {
18+
externalDocumentationLink(delegateClosureOf<Builder> {
19+
this.url = URL(url)
20+
packageListUrl = packageList.toPath().toUri().toURL()
21+
})
22+
}
23+
}

buildSrc/src/main/kotlin/MavenCentral.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@file:Suppress("UnstableApiUsage")
66

77
import org.gradle.api.Project
8-
import org.gradle.api.provider.Property
98
import org.gradle.api.publish.maven.MavenPom
109

1110
// --------------- pom configuration ---------------
@@ -36,7 +35,3 @@ fun MavenPom.configureMavenCentralMetadata(project: Project) {
3635
url by "https://github.com/Kotlin/kotlinx.coroutines"
3736
}
3837
}
39-
40-
private infix fun <T> Property<T>.by(value: T) {
41-
set(value)
42-
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("UnstableApiUsage")
6+
7+
import org.gradle.api.provider.*
8+
9+
infix fun <T> Property<T>.by(value: T) {
10+
set(value)
11+
}

buildSrc/src/main/kotlin/RunR8.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import org.gradle.api.tasks.InputFile
2+
import org.gradle.api.tasks.InputFiles
3+
import org.gradle.api.tasks.JavaExec
4+
import org.gradle.api.tasks.OutputDirectory
5+
import org.gradle.api.tasks.bundling.Zip
6+
import org.gradle.kotlin.dsl.get
7+
import org.gradle.kotlin.dsl.named
8+
import java.io.File
9+
10+
open class RunR8 : JavaExec() {
11+
12+
@OutputDirectory
13+
lateinit var outputDex: File
14+
15+
@InputFile
16+
lateinit var inputConfig: File
17+
18+
@InputFile
19+
val inputConfigCommon: File = File("testdata/r8-test-common.pro")
20+
21+
@InputFiles
22+
val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath
23+
24+
init {
25+
classpath = project.configurations["r8"]
26+
main = "com.android.tools.r8.R8"
27+
}
28+
29+
override fun exec() {
30+
// Resolve classpath only during execution
31+
val arguments = mutableListOf(
32+
"--release",
33+
"--no-desugaring",
34+
"--output", outputDex.absolutePath,
35+
"--pg-conf", inputConfig.absolutePath
36+
)
37+
arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath })
38+
arguments.add(jarFile.absolutePath)
39+
40+
args = arguments
41+
42+
project.delete(outputDex)
43+
outputDex.mkdirs()
44+
45+
super.exec()
46+
}
47+
}

buildSrc/src/main/kotlin/UnpackAar.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import org.gradle.api.artifacts.transform.InputArtifact
2+
import org.gradle.api.artifacts.transform.TransformAction
3+
import org.gradle.api.artifacts.transform.TransformOutputs
4+
import org.gradle.api.artifacts.transform.TransformParameters
5+
import org.gradle.api.file.FileSystemLocation
6+
import org.gradle.api.provider.Provider
7+
import java.io.File
8+
import java.nio.file.Files
9+
import java.util.zip.ZipEntry
10+
import java.util.zip.ZipFile
11+
12+
@Suppress("UnstableApiUsage")
13+
abstract class UnpackAar : TransformAction<TransformParameters.None> {
14+
@get:InputArtifact
15+
abstract val inputArtifact: Provider<FileSystemLocation>
16+
17+
override fun transform(outputs: TransformOutputs) {
18+
ZipFile(inputArtifact.get().asFile).use { zip ->
19+
zip.entries().asSequence()
20+
.filter { !it.isDirectory }
21+
.filter { it.name.endsWith(".jar") }
22+
.forEach { zip.unzip(it, outputs.file(it.name)) }
23+
}
24+
}
25+
}
26+
27+
private fun ZipFile.unzip(entry: ZipEntry, output: File) {
28+
getInputStream(entry).use {
29+
Files.copy(it, output.toPath())
30+
}
31+
}

gradle/compile-js.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@
44

55
// Platform-specific configuration to compile JS modules
66

7-
apply plugin: 'kotlin2js'
7+
apply plugin: 'org.jetbrains.kotlin.js'
8+
9+
kotlin.sourceSets {
10+
main.kotlin.srcDirs = ['src']
11+
test.kotlin.srcDirs = ['test']
12+
main.resources.srcDirs = ['resources']
13+
test.resources.srcDirs = ['test-resources']
14+
}
815

916
dependencies {
1017
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
1118
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
1219
}
1320

14-
tasks.withType(compileKotlin2Js.getClass()) {
21+
tasks.withType(compileKotlinJs.getClass()) {
1522
kotlinOptions {
1623
moduleKind = "umd"
1724
sourceMap = true
1825
metaInfo = true
1926
}
2027
}
2128

22-
compileKotlin2Js {
29+
compileKotlinJs {
2330
kotlinOptions {
2431
// drop -js suffix from outputFile
2532
def baseName = project.name - "-js"

gradle/compile-jvm-multiplatform.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
sourceCompatibility = 1.6
66
targetCompatibility = 1.6
77

8-
repositories {
9-
maven { url "https://dl.bintray.com/devexperts/Maven/" }
10-
}
11-
128
kotlin {
139
targets {
1410
fromPreset(presets.jvm, 'jvm')

0 commit comments

Comments
 (0)