Skip to content

Commit

Permalink
Transition to the Gradle kts
Browse files Browse the repository at this point in the history
Non-deprecated 'jmhJar' configuration (Kotlin#2032) (+9 squashed commits)
Squashed commits:
[8d07d36] Use new Kotlin/JS plugin (Kotlin#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
  • Loading branch information
turansky authored and qwwdfsad committed Aug 25, 2020
1 parent 63156a8 commit 964cd92
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 195 deletions.
12 changes: 7 additions & 5 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("UnstableApiUsage")

import me.champeau.gradle.*
import org.jetbrains.kotlin.gradle.tasks.*

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

tasks.named<Jar>("jmhJar") {
baseName = "benchmarks"
classifier = null
version = null
destinationDir = file("$rootDir")
archiveBaseName by "benchmarks"
archiveClassifier by null
archiveVersion by null
destinationDirectory.file("$rootDir")
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }
}

// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != 'example-frontend-js' && it.name != coreModule }) {
sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
Expand Down
16 changes: 16 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import java.util.*

plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
maven("https://kotlin.bintray.com/kotlin-eap")
maven("https://kotlin.bintray.com/kotlin-dev")
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}

val props = Properties().apply {
file("../gradle.properties").inputStream().use { load(it) }
}

fun version(target: String): String =
props.getProperty("${target}_version")

dependencies {
implementation(kotlin("gradle-plugin", version("kotlin")))
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${version("dokka")}")
}
23 changes: 23 additions & 0 deletions buildSrc/src/main/kotlin/Dokka.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.gradle.api.Project
import org.gradle.kotlin.dsl.delegateClosureOf
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.File
import java.net.URL

fun Project.externalDocumentationLink(
url: String,
packageList: File = projectDir.resolve("package.list")
) {
tasks.withType<DokkaTask>().configureEach {
externalDocumentationLink(delegateClosureOf<Builder> {
this.url = URL(url)
packageListUrl = packageList.toPath().toUri().toURL()
})
}
}
5 changes: 0 additions & 5 deletions buildSrc/src/main/kotlin/MavenCentral.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@file:Suppress("UnstableApiUsage")

import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.publish.maven.MavenPom

// --------------- pom configuration ---------------
Expand Down Expand Up @@ -36,7 +35,3 @@ fun MavenPom.configureMavenCentralMetadata(project: Project) {
url by "https://github.com/Kotlin/kotlinx.coroutines"
}
}

private infix fun <T> Property<T>.by(value: T) {
set(value)
}
11 changes: 11 additions & 0 deletions buildSrc/src/main/kotlin/Properties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("UnstableApiUsage")

import org.gradle.api.provider.*

infix fun <T> Property<T>.by(value: T) {
set(value)
}
47 changes: 47 additions & 0 deletions buildSrc/src/main/kotlin/RunR8.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.bundling.Zip
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import java.io.File

open class RunR8 : JavaExec() {

@OutputDirectory
lateinit var outputDex: File

@InputFile
lateinit var inputConfig: File

@InputFile
val inputConfigCommon: File = File("testdata/r8-test-common.pro")

@InputFiles
val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath

init {
classpath = project.configurations["r8"]
main = "com.android.tools.r8.R8"
}

override fun exec() {
// Resolve classpath only during execution
val arguments = mutableListOf(
"--release",
"--no-desugaring",
"--output", outputDex.absolutePath,
"--pg-conf", inputConfig.absolutePath
)
arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath })
arguments.add(jarFile.absolutePath)

args = arguments

project.delete(outputDex)
outputDex.mkdirs()

super.exec()
}
}
31 changes: 31 additions & 0 deletions buildSrc/src/main/kotlin/UnpackAar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.gradle.api.artifacts.transform.InputArtifact
import org.gradle.api.artifacts.transform.TransformAction
import org.gradle.api.artifacts.transform.TransformOutputs
import org.gradle.api.artifacts.transform.TransformParameters
import org.gradle.api.file.FileSystemLocation
import org.gradle.api.provider.Provider
import java.io.File
import java.nio.file.Files
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

@Suppress("UnstableApiUsage")
abstract class UnpackAar : TransformAction<TransformParameters.None> {
@get:InputArtifact
abstract val inputArtifact: Provider<FileSystemLocation>

override fun transform(outputs: TransformOutputs) {
ZipFile(inputArtifact.get().asFile).use { zip ->
zip.entries().asSequence()
.filter { !it.isDirectory }
.filter { it.name.endsWith(".jar") }
.forEach { zip.unzip(it, outputs.file(it.name)) }
}
}
}

private fun ZipFile.unzip(entry: ZipEntry, output: File) {
getInputStream(entry).use {
Files.copy(it, output.toPath())
}
}
13 changes: 10 additions & 3 deletions gradle/compile-js.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@

// Platform-specific configuration to compile JS modules

apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.kotlin.js'

kotlin.sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['test-resources']
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}

tasks.withType(compileKotlin2Js.getClass()) {
tasks.withType(compileKotlinJs.getClass()) {
kotlinOptions {
moduleKind = "umd"
sourceMap = true
metaInfo = true
}
}

compileKotlin2Js {
compileKotlinJs {
kotlinOptions {
// drop -js suffix from outputFile
def baseName = project.name - "-js"
Expand Down
4 changes: 0 additions & 4 deletions gradle/compile-jvm-multiplatform.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
sourceCompatibility = 1.6
targetCompatibility = 1.6

repositories {
maven { url "https://dl.bintray.com/devexperts/Maven/" }
}

kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
Expand Down
4 changes: 0 additions & 4 deletions gradle/compile-jvm.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ dependencies {
testCompile "junit:junit:$junit_version"
}

repositories {
maven { url "https://dl.bintray.com/devexperts/Maven/" }
}

compileKotlin {
kotlinOptions {
freeCompilerArgs += ['-Xexplicit-api=strict']
Expand Down
34 changes: 0 additions & 34 deletions integration/kotlinx-coroutines-play-services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.gradle.api.artifacts.transform.*

import java.nio.file.Files
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

ext.tasks_version = '16.0.1'

def artifactType = Attribute.of("artifactType", String)
Expand Down Expand Up @@ -49,31 +43,3 @@ tasks.withType(dokka.getClass()) {
packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL()
}
}

abstract class UnpackAar implements TransformAction<TransformParameters.None> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()

@Override
void transform(TransformOutputs outputs) {
ZipFile zip = new ZipFile(inputArtifact.get().asFile)
try {
for (entry in zip.entries()) {
if (!entry.isDirectory() && entry.name.endsWith(".jar")) {
unzipEntryTo(zip, entry, outputs.file(entry.name))
}
}
} finally {
zip.close()
}
}

private static void unzipEntryTo(ZipFile zip, ZipEntry entry, File output) {
InputStream stream = zip.getInputStream(entry)
try {
Files.copy(stream, output.toPath())
} finally {
stream.close()
}
}
}
31 changes: 3 additions & 28 deletions js/example-frontend-js/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,19 @@
apply plugin: 'kotlin-dce-js'
apply from: rootProject.file('gradle/node-js.gradle')

// Workaround resolving new Gradle metadata with kotlin2js
// TODO: Remove once KT-37188 is fixed
try {
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute")
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
configurations {
matching {
it.name.endsWith("Classpath")
}.forEach {
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
}
}
} catch (java.lang.ClassNotFoundException e) {
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
}

dependencies {
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
}

compileKotlin2Js {
compileKotlinJs {
kotlinOptions {
main = "call"
}
}

task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
task bundle(type: NpmTask, dependsOn: [npmInstall, build]) {
inputs.files(fileTree("$buildDir/kotlin-js-min/main"))
inputs.files(fileTree("$buildDir/kotlin-js-min/legacy/main"))
inputs.files(fileTree(file("src/main/web")))
inputs.file("npm/webpack.config.js")
outputs.dir("$buildDir/dist")
Expand All @@ -44,11 +27,3 @@ task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
task start(type: NpmTask, dependsOn: bundle) {
args = ["run", "start"]
}

// we have not tests but kotlin-dce-js still tries to work with them and crashed.
// todo: Remove when KT-22028 is fixed
afterEvaluate {
if (tasks.findByName('unpackDependenciesTestKotlinJs')) {
tasks.unpackDependenciesTestKotlinJs.enabled = false
}
}
1 change: 1 addition & 0 deletions js/example-frontend-js/npm/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
resolve: {
modules: [
path.resolve(__dirname, "kotlin-js-min/main"),
path.resolve(__dirname, "kotlin-js-min/legacy/main"),
path.resolve(__dirname, "../src/main/web/")
]
},
Expand Down
Loading

0 comments on commit 964cd92

Please sign in to comment.