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

+7-5
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

+1-1
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

+16
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

+23
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

-5
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-
}
+11
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

+47
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

+31
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

+10-3
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

-4
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')

gradle/compile-jvm.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ dependencies {
1919
testCompile "junit:junit:$junit_version"
2020
}
2121

22-
repositories {
23-
maven { url "https://dl.bintray.com/devexperts/Maven/" }
24-
}
25-
2622
compileKotlin {
2723
kotlinOptions {
2824
freeCompilerArgs += ['-Xexplicit-api=strict']

integration/kotlinx-coroutines-play-services/build.gradle

-34
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import org.gradle.api.artifacts.transform.*
6-
7-
import java.nio.file.Files
8-
import java.util.zip.ZipEntry
9-
import java.util.zip.ZipFile
10-
115
ext.tasks_version = '16.0.1'
126

137
def artifactType = Attribute.of("artifactType", String)
@@ -49,31 +43,3 @@ tasks.withType(dokka.getClass()) {
4943
packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL()
5044
}
5145
}
52-
53-
abstract class UnpackAar implements TransformAction<TransformParameters.None> {
54-
@InputArtifact
55-
abstract Provider<FileSystemLocation> getInputArtifact()
56-
57-
@Override
58-
void transform(TransformOutputs outputs) {
59-
ZipFile zip = new ZipFile(inputArtifact.get().asFile)
60-
try {
61-
for (entry in zip.entries()) {
62-
if (!entry.isDirectory() && entry.name.endsWith(".jar")) {
63-
unzipEntryTo(zip, entry, outputs.file(entry.name))
64-
}
65-
}
66-
} finally {
67-
zip.close()
68-
}
69-
}
70-
71-
private static void unzipEntryTo(ZipFile zip, ZipEntry entry, File output) {
72-
InputStream stream = zip.getInputStream(entry)
73-
try {
74-
Files.copy(stream, output.toPath())
75-
} finally {
76-
stream.close()
77-
}
78-
}
79-
}

js/example-frontend-js/build.gradle

+3-28
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,19 @@
55
apply plugin: 'kotlin-dce-js'
66
apply from: rootProject.file('gradle/node-js.gradle')
77

8-
// Workaround resolving new Gradle metadata with kotlin2js
9-
// TODO: Remove once KT-37188 is fixed
10-
try {
11-
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute")
12-
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
13-
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
14-
configurations {
15-
matching {
16-
it.name.endsWith("Classpath")
17-
}.forEach {
18-
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
19-
}
20-
}
21-
} catch (java.lang.ClassNotFoundException e) {
22-
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
23-
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
24-
}
25-
268
dependencies {
279
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
2810
}
2911

30-
compileKotlin2Js {
12+
compileKotlinJs {
3113
kotlinOptions {
3214
main = "call"
3315
}
3416
}
3517

36-
task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
18+
task bundle(type: NpmTask, dependsOn: [npmInstall, build]) {
3719
inputs.files(fileTree("$buildDir/kotlin-js-min/main"))
20+
inputs.files(fileTree("$buildDir/kotlin-js-min/legacy/main"))
3821
inputs.files(fileTree(file("src/main/web")))
3922
inputs.file("npm/webpack.config.js")
4023
outputs.dir("$buildDir/dist")
@@ -44,11 +27,3 @@ task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
4427
task start(type: NpmTask, dependsOn: bundle) {
4528
args = ["run", "start"]
4629
}
47-
48-
// we have not tests but kotlin-dce-js still tries to work with them and crashed.
49-
// todo: Remove when KT-22028 is fixed
50-
afterEvaluate {
51-
if (tasks.findByName('unpackDependenciesTestKotlinJs')) {
52-
tasks.unpackDependenciesTestKotlinJs.enabled = false
53-
}
54-
}

js/example-frontend-js/npm/webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
resolve: {
3939
modules: [
4040
path.resolve(__dirname, "kotlin-js-min/main"),
41+
path.resolve(__dirname, "kotlin-js-min/legacy/main"),
4142
path.resolve(__dirname, "../src/main/web/")
4243
]
4344
},

0 commit comments

Comments
 (0)