Skip to content

Commit 2bf1519

Browse files
committed
Translate *.gradle to *.gradle.kts
1 parent 07226cc commit 2bf1519

File tree

10 files changed

+318
-278
lines changed

10 files changed

+318
-278
lines changed

build.gradle.kts

Lines changed: 78 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,84 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
2-
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
2+
import org.jetbrains.kotlin.gradle.dsl.*
3+
import org.gradle.kotlin.dsl.*
34
import org.jetbrains.kotlin.konan.target.HostManager
45

5-
import static Projects.*
6-
76
buildscript {
8-
ext.kotlin_version = CommunityProjectsBuild.getOverriddenKotlinVersion(rootProject)
9-
10-
if (CommunityProjectsBuild.shouldUseLocalMaven(rootProject)) {
7+
if (shouldUseLocalMaven(rootProject)) {
118
repositories {
129
mavenLocal()
1310
}
1411
}
1512

1613
repositories {
1714
mavenCentral()
18-
maven { url "https://plugins.gradle.org/m2/" }
19-
CommunityProjectsBuild.addDevRepositoryIfEnabled(delegate, project)
15+
maven(url = "https://plugins.gradle.org/m2/")
16+
addDevRepositoryIfEnabled(this, project)
2017
mavenLocal()
2118
}
2219

2320
dependencies {
2421
// Please ensure that atomicfu-gradle-plugin is added to the classpath first, do not change the order, for details see #3984.
2522
// The corresponding issue in kotlinx-atomicfu: https://github.com/Kotlin/kotlinx-atomicfu/issues/384
26-
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
27-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
28-
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
29-
classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
30-
classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
31-
classpath "ru.vyarus:gradle-animalsniffer-plugin:$animalsniffer_version" // Android API check
32-
classpath "org.jetbrains.kotlin:atomicfu:$kotlin_version"
33-
classpath "org.jetbrains.kotlinx:kover-gradle-plugin:$kover_version"
23+
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${version("atomicfu")}")
24+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${version("kotlin")}")
25+
classpath("org.jetbrains.dokka:dokka-gradle-plugin:${version("dokka")}")
26+
classpath("org.jetbrains.kotlinx:kotlinx-knit:${version("knit")}")
27+
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${version("binary_compatibility_validator")}")
28+
classpath("ru.vyarus:gradle-animalsniffer-plugin:${version("animalsniffer")}") // Android API check
29+
classpath("org.jetbrains.kotlin:atomicfu:${version("kotlin")}")
30+
classpath("org.jetbrains.kotlinx:kover-gradle-plugin:${version("kover")}")
3431

3532
// JMH plugins
36-
classpath "gradle.plugin.com.github.johnrengelman:shadow:$shadow_version"
33+
classpath("gradle.plugin.com.github.johnrengelman:shadow:${version("shadow")}")
3734
}
3835

39-
CacheRedirector.configureBuildScript(buildscript, rootProject)
40-
}
41-
42-
// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
43-
def configureKotlinJvmPlatform(configuration) {
44-
configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
36+
with(CacheRedirector) { buildscript.configureBuildScript(rootProject) }
4537
}
4638

4739
// Configure subprojects with Kotlin sources
48-
apply plugin: "configure-compilation-conventions"
40+
apply(plugin = "configure-compilation-conventions")
4941

5042
allprojects {
5143
// the only place where HostManager could be instantiated
52-
project.ext.hostManager = new HostManager()
53-
def deployVersion = properties['DeployVersion']
44+
project.ext["hostManager"] = HostManager()
45+
val deployVersion = properties["DeployVersion"]
5446
if (deployVersion != null) version = deployVersion
5547

56-
if (CommunityProjectsBuild.isSnapshotTrainEnabled(rootProject)) {
57-
def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
58-
if (!skipSnapshotChecks && version != atomicfu_version) {
59-
throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
48+
if (isSnapshotTrainEnabled(rootProject)) {
49+
val skipSnapshotChecks = rootProject.properties["skip_snapshot_checks"] != null
50+
if (!skipSnapshotChecks && version != version("atomicfu")) {
51+
throw IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden (${version("atomicfu")}) for $this")
6052
}
6153
}
6254

63-
if (CommunityProjectsBuild.shouldUseLocalMaven(rootProject)) {
55+
if (shouldUseLocalMaven(rootProject)) {
6456
repositories {
6557
mavenLocal()
6658
}
6759
}
6860

6961
// This project property is set during nightly stress test
70-
def stressTest = project.properties['stressTest']
71-
62+
val stressTest = project.properties["stressTest"]
7263
// Copy it to all test tasks
73-
tasks.withType(Test).configureEach {
74-
systemProperty 'stressTest', stressTest
64+
tasks.withType(Test::class).configureEach {
65+
if (stressTest != null) {
66+
systemProperty("stressTest", stressTest)
67+
}
7568
}
7669
}
7770

78-
apply plugin: "binary-compatibility-validator"
79-
apply plugin: "base"
80-
apply plugin: "kover-conventions"
71+
plugins {
72+
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
73+
}
74+
75+
apply(plugin = "base")
76+
apply(plugin = "kover-conventions")
8177

8278
apiValidation {
83-
ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
84-
if (CommunityProjectsBuild.isSnapshotTrainEnabled(rootProject)) {
85-
ignoredProjects.add(coreModule)
79+
ignoredProjects += unpublished + listOf("kotlinx-coroutines-bom")
80+
if (isSnapshotTrainEnabled(rootProject)) {
81+
ignoredProjects += coreModule
8682
}
8783
ignoredPackages += "kotlinx.coroutines.internal"
8884
}
@@ -96,69 +92,79 @@ allprojects {
9692
*/
9793
google()
9894
mavenCentral()
99-
CommunityProjectsBuild.addDevRepositoryIfEnabled(delegate, project)
95+
addDevRepositoryIfEnabled(this, project)
10096
}
10197
}
10298

10399
// needs to be before evaluationDependsOn due to weird Gradle ordering
104-
apply plugin: "animalsniffer-conventions"
105-
106-
configure(subprojects.findAll { !sourceless.contains(it.name) }) {
107-
if (isMultiplatform(it)) {
108-
apply plugin: 'kotlin-multiplatform'
109-
apply plugin: "kotlin-multiplatform-conventions"
110-
} else if (PlatformKt.platformOf(it) == "jvm") {
111-
apply plugin: "kotlin-jvm-conventions"
100+
apply(plugin = "animalsniffer-conventions")
101+
102+
configure(subprojects.filter { !sourceless.contains(it.name) }) {
103+
if (isMultiplatform) {
104+
apply(plugin = "kotlin-multiplatform")
105+
apply(plugin = "kotlin-multiplatform-conventions")
106+
} else if (platformOf(this) == "jvm") {
107+
apply(plugin = "kotlin-jvm-conventions")
112108
} else {
113-
def platform = PlatformKt.platformOf(it)
109+
val platform = platformOf(this)
114110
throw IllegalStateException("No configuration rules for $platform")
115111
}
116112
}
117113

118114
// Add dependency to the core module in all the other subprojects.
119-
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
115+
configure(subprojects.filter { !sourceless.contains(it.name) && it.name != coreModule }) {
120116
evaluationDependsOn(":$coreModule")
121-
if (isMultiplatform(it)) {
122-
kotlin.sourceSets.commonMain.dependencies {
123-
api project(":$coreModule")
124-
}
125-
kotlin.sourceSets.jvmTest.dependencies {
126-
implementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
117+
val jvmTestDependency = project(":$coreModule")
118+
.extensions.getByType(KotlinMultiplatformExtension::class)
119+
.targets["jvm"].compilations["test"].output.allOutputs
120+
if (isMultiplatform) {
121+
configure<KotlinMultiplatformExtension> {
122+
sourceSets {
123+
commonMain {
124+
dependencies {
125+
api(project(":$coreModule"))
126+
}
127+
}
128+
jvmTest {
129+
dependencies {
130+
implementation(jvmTestDependency)
131+
}
132+
}
133+
}
127134
}
128135
} else {
129136
dependencies {
130-
api project(":$coreModule")
137+
add("api", project(":$coreModule"))
131138
// the only way IDEA can resolve test classes
132-
testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
139+
add("testImplementation", jvmTestDependency)
133140
}
134141
}
135142
}
136143

137-
apply plugin: "bom-conventions"
138-
apply plugin: "java-modularity-conventions"
139-
apply plugin: "version-file-conventions"
144+
apply(plugin = "bom-conventions")
145+
apply(plugin = "java-modularity-conventions")
146+
apply(plugin = "version-file-conventions")
140147

141-
CommunityProjectsBuild.configureCommunityBuildTweaks(rootProject)
148+
rootProject.configureCommunityBuildTweaks()
142149

143-
apply plugin: "source-set-conventions"
144-
apply plugin: "dokka-conventions"
145-
apply plugin: "knit-conventions"
150+
apply(plugin = "source-set-conventions")
151+
apply(plugin = "dokka-conventions")
152+
apply(plugin = "knit-conventions")
146153

147154
/*
148155
* TODO: core and non-core cannot be configured via 'configure(subprojects)'
149156
* because of 'afterEvaluate' issue. This one should be migrated to
150157
* `plugins { id("pub-conventions") }` eventually
151158
*/
152-
configure(subprojects.findAll {
159+
configure(subprojects.filter {
153160
!unpublished.contains(it.name) && it.name != coreModule
154161
}) {
155-
apply plugin: "pub-conventions"
162+
apply(plugin = "pub-conventions")
156163
}
157164

158165
AuxBuildConfiguration.configure(rootProject)
159-
PublishingKt.registerTopLevelDeployTask(rootProject)
166+
rootProject.registerTopLevelDeployTask()
160167

161168
// Report Kotlin compiler version when building project
162-
println("Using Kotlin compiler version: $KotlinCompilerVersion.VERSION")
163-
169+
println("Using Kotlin compiler version: ${KotlinCompilerVersion.VERSION}")
164170

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ dependencies {
6161
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
6262
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
6363
}
64-
64+
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.4.9")
6565
implementation("org.jetbrains.kotlinx:kotlinx-knit:${version("knit")}")
6666
}
Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
1+
import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
2+
13
plugins {
2-
id 'java-platform'
4+
id("java-platform")
35
}
46

5-
def name = project.name
7+
val name = project.name
68

79
dependencies {
810
constraints {
9-
rootProject.subprojects.each {
10-
if (Projects.unpublished.contains(it.name)) return
11-
if (it.name == name) return
12-
if (!it.plugins.hasPlugin('maven-publish')) return
11+
rootProject.subprojects.forEach {
12+
if (unpublished.contains(it.name)) return@forEach
13+
if (it.name == name) return@forEach
14+
if (!it.plugins.hasPlugin("maven-publish")) return@forEach
1315
evaluationDependsOn(it.path)
1416
it.publishing.publications.all {
15-
if (it.artifactId.endsWith("-kotlinMultiplatform")) return
16-
if (it.artifactId.endsWith("-metadata")) return
17+
this as MavenPublication
18+
if (artifactId.endsWith("-kotlinMultiplatform")) return@all
19+
if (artifactId.endsWith("-metadata")) return@all
1720
// Skip platform artifacts (like *-linuxx64, *-macosx64)
1821
// It leads to inconsistent bom when publishing from different platforms
1922
// (e.g. on linux it will include only linuxx64 artifacts and no macosx64)
2023
// It shouldn't be a problem as usually consumers need to use generic *-native artifact
2124
// Gradle will choose correct variant by using metadata attributes
22-
if (it.artifacts.any { it.extension == 'klib' }) return
23-
api(group: it.groupId, name: it.artifactId, version: it.version)
25+
if (artifacts.any { it.extension == "klib" }) return@all
26+
this@constraints.api(mapOf("group" to groupId, "name" to artifactId, "version" to version))
2427
}
2528
}
2629
}
2730
}
2831

2932
publishing {
3033
publications {
31-
mavenBom(MavenPublication) {
32-
from components.javaPlatform
34+
val mavenBom by creating(MavenPublication::class) {
35+
from(components["javaPlatform"])
3336
}
3437
// Disable metadata publication
35-
it.each { pub ->
36-
pub.moduleDescriptorGenerator = null
38+
forEach { pub ->
39+
pub as DefaultMavenPublication
40+
pub.unsetModuleDescriptorGenerator()
3741
tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all {
3842
onlyIf { false }
3943
}
4044
}
4145
}
4246
}
47+
48+
fun DefaultMavenPublication.unsetModuleDescriptorGenerator() {
49+
@Suppress("NULL_FOR_NONNULL_TYPE")
50+
val generator: TaskProvider<Task> = null
51+
setModuleDescriptorGenerator(generator)
52+
}

0 commit comments

Comments
 (0)