Skip to content

Commit 7937302

Browse files
committed
Update to 1.5.0 and apply sam-with-receiver plugin
In order to use gradle API in a similar way as it is used in build scripts.
1 parent 25e3650 commit 7937302

File tree

9 files changed

+82
-68
lines changed

9 files changed

+82
-68
lines changed

build.gradle

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import java.nio.file.Files
2-
import java.nio.file.Paths
32

43
buildscript {
54
repositories {
65
mavenCentral()
76
}
7+
dependencies {
8+
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:$kotlin_version")
9+
}
810
}
911

1012
plugins {
1113
id 'maven-publish'
1214
id 'java-gradle-plugin'
13-
id 'org.jetbrains.kotlin.jvm' version "1.4.0"
15+
id 'org.jetbrains.kotlin.jvm'
1416
}
17+
apply plugin: "kotlin-sam-with-receiver"
1518

1619
// Load `local.properties` file, if it exists. You can put your spaceUser and spaceToken values there, that file is ignored by git
17-
if (Files.exists(Paths.get("$project.rootDir/local.properties"))) {
18-
def localProperties = new Properties()
19-
localProperties.load(new FileInputStream("$project.rootDir/local.properties"))
20-
localProperties.each { prop -> project.ext.set(prop.key, prop.value) }
20+
def localPropertiesFile = file("$project.rootDir/local.properties")
21+
if (Files.exists(localPropertiesFile.toPath())) {
22+
localPropertiesFile.withReader { reader ->
23+
def localProperties = new Properties()
24+
localProperties.load(reader)
25+
localProperties.each { prop -> project.ext.set(prop.key, prop.value) }
26+
}
2127
}
2228

2329
repositories {
@@ -70,6 +76,10 @@ dependencies {
7076
testImplementation 'junit:junit:4.12'
7177
}
7278

79+
samWithReceiver {
80+
annotation("org.gradle.api.HasImplicitReceiver")
81+
}
82+
7383
apply from: 'publish.gradle'
7484

7585
if (project.hasProperty("teamcity")) {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ kotlin.code.style=official
44
version = 0.3.0
55
group = kotlinx.team
66

7-
kotlin_version=1.4.0
7+
kotlin_version=1.5.0

main/src/kotlinx/team/infra/InfraPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class InfraPlugin : Plugin<Project> {
4040
configureNativeMultiplatform()
4141

4242
subprojects {
43-
it.applyModule()
43+
applyModule()
4444
}
4545
}
4646

main/src/kotlinx/team/infra/NativeMultiplatform.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ fun Project.configureNativeMultiplatform() {
1717
}
1818

1919
val ideaActive = System.getProperty("idea.active")?.toBoolean() ?: false
20-
subprojects { subproject ->
20+
subprojects {
21+
val subproject = this
2122
// Checking for MPP beforeEvaluate is too early, and in afterEvaluate too late because node plugin breaks
22-
subproject.pluginManager.withPlugin("kotlin-multiplatform") { plugin ->
23+
subproject.pluginManager.withPlugin("kotlin-multiplatform") {
2324
val kotlin = subproject.extensions.findByType(multiplatformExtensionClass)
2425
if (kotlin == null) {
2526
logger.infra("Skipping native configuration for $subproject because multiplatform plugin has not been configured properly")
@@ -87,8 +88,8 @@ class NativeIdeaInfraExtension(project: Project, kotlin: KotlinMultiplatformExte
8788
}
8889

8990
project.afterEvaluate {
90-
kotlin.sourceSets.getByName("${sourceSetName}Main") { sourceSet ->
91-
sourceSet.kotlin.srcDir("${hostPreset.name}Main/src")
91+
kotlin.sourceSets.getByName("${sourceSetName}Main") {
92+
kotlin.srcDir("${hostPreset.name}Main/src")
9293
}
9394
}
9495
}
@@ -120,11 +121,11 @@ class NativeBuildInfraExtension(project: Project, kotlin: KotlinMultiplatformExt
120121
sharedConfigs.forEach { config -> config() }
121122
}
122123

123-
kotlin.sourceSets.getByName("${preset.name}Main") { sourceSet ->
124-
sourceSet.dependsOn(mainSourceSet)
124+
kotlin.sourceSets.getByName("${preset.name}Main") {
125+
dependsOn(mainSourceSet)
125126
}
126-
kotlin.sourceSets.getByName("${preset.name}Test") { sourceSet ->
127-
sourceSet.dependsOn(testSourceSet)
127+
kotlin.sourceSets.getByName("${preset.name}Test") {
128+
dependsOn(testSourceSet)
128129
}
129130
}
130131

main/src/kotlinx/team/infra/Publishing.kt

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ private fun Project.createBuildRepository(name: String, rootBuildLocal: Task) {
129129
if (rootBuildLocal !== compositeTask)
130130
rootBuildLocal.dependsOn(compositeTask)
131131

132-
extensions.configure(PublishingExtension::class.java) { publishing ->
133-
val repo = publishing.repositories.maven { repo ->
134-
repo.name = name
135-
repo.setUrl(dir)
132+
extensions.configure(PublishingExtension::class.java) {
133+
val repo = repositories.maven {
134+
this.name = name
135+
this.setUrl(dir)
136136
}
137137

138138
afterEvaluate {
139139
tasks.named("clean", Delete::class.java) {
140-
it.delete(dir)
140+
delete(dir)
141141
}
142142

143-
tasks.withType(PublishToMavenRepository::class.java) { task ->
144-
if (task.repository == repo) {
145-
compositeTask.dependsOn(task)
143+
tasks.withType(PublishToMavenRepository::class.java) {
144+
if (this.repository == repo) {
145+
compositeTask.dependsOn(this)
146146
}
147147
}
148148
}
@@ -196,13 +196,13 @@ private fun Project.createSonatypeRepository() {
196196
val password = project.sonatypePassword
197197
?: throw KotlinInfrastructureException("Cannot setup publication. Password (API key) has not been specified.")
198198

199-
extensions.configure(PublishingExtension::class.java) { publishing ->
200-
publishing.repositories.maven { repo ->
201-
repo.name = "sonatype"
202-
repo.url = sonatypeRepositoryUri()
203-
repo.credentials { credentials ->
204-
credentials.username = username
205-
credentials.password = password.trim()
199+
extensions.configure(PublishingExtension::class.java) {
200+
repositories.maven {
201+
name = "sonatype"
202+
url = sonatypeRepositoryUri()
203+
credentials {
204+
this.username = username
205+
this.password = password.trim()
206206
}
207207
}
208208
}
@@ -215,9 +215,9 @@ private fun Project.configurePublications(publishing: PublishingConfiguration) {
215215
val javadocJar = tasks.create("javadocJar", Jar::class.java).apply {
216216
archiveClassifier.set("javadoc")
217217
}
218-
extensions.configure(PublishingExtension::class.java) { publishingExtension ->
219-
publishingExtension.publications.all {
220-
with(it as MavenPublication) {
218+
extensions.configure(PublishingExtension::class.java) {
219+
publications.all {
220+
with(this as MavenPublication) {
221221
artifact(javadocJar)
222222
configureRequiredPomAttributes(project, publishing)
223223
}
@@ -226,34 +226,33 @@ private fun Project.configurePublications(publishing: PublishingConfiguration) {
226226
}
227227

228228
fun Project.mavenPublicationsPom(action: Action<MavenPom>) {
229-
extensions.configure(PublishingExtension::class.java) { publishingExtension ->
230-
publishingExtension.publications.all {
231-
action.execute((it as MavenPublication).pom)
229+
extensions.configure(PublishingExtension::class.java) {
230+
publications.all {
231+
action.execute((this as MavenPublication).pom)
232232
}
233233
}
234234
}
235235

236236
private fun MavenPublication.configureRequiredPomAttributes(project: Project, publishing: PublishingConfiguration) {
237237
val publication = this
238-
// TODO: get rid of 'it's
239238
pom {
240-
it.name.set(publication.artifactId)
241-
it.description.set(project.description ?: publication.artifactId)
242-
it.url.set(publishing.libraryRepoUrl)
243-
it.licenses {
244-
it.license {
245-
it.name.set("The Apache License, Version 2.0")
246-
it.url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
239+
name.set(publication.artifactId)
240+
description.set(project.description ?: publication.artifactId)
241+
url.set(publishing.libraryRepoUrl)
242+
licenses {
243+
license {
244+
name.set("The Apache License, Version 2.0")
245+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
247246
}
248247
}
249-
it.scm {
250-
it.url.set(publishing.libraryRepoUrl)
248+
scm {
249+
url.set(publishing.libraryRepoUrl)
251250
}
252-
it.developers {
253-
it.developer {
254-
it.name.set("JetBrains Team")
255-
it.organization.set("JetBrains")
256-
it.organizationUrl.set("https://www.jetbrains.com")
251+
developers {
252+
developer {
253+
name.set("JetBrains Team")
254+
organization.set("JetBrains")
255+
organizationUrl.set("https://www.jetbrains.com")
257256
}
258257
}
259258
}
@@ -267,8 +266,8 @@ private fun Project.configureSigning() {
267266

268267
if (keyId != null) {
269268
project.extensions.configure<SigningExtension>("signing") {
270-
it.useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
271-
it.sign(extensions.getByType(PublishingExtension::class.java).publications) // all publications
269+
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
270+
sign(extensions.getByType(PublishingExtension::class.java).publications) // all publications
272271
}
273272
} else {
274273
logger.warn("INFRA: signing key id is not specified, artifact signing is not enabled.")

main/src/kotlinx/team/infra/TeamCity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun Project.configureTeamCityLogging() {
1717
println("##teamcity[buildNumber '${project.version}${teamcitySuffix?.let { " ($it)" } ?: ""}']")
1818

1919
gradle.taskGraph.beforeTask {
20-
println("##teamcity[progressMessage 'Gradle: ${it.project.path}:${it.name}']")
20+
println("##teamcity[progressMessage 'Gradle: ${this.project.path}:${this.name}']")
2121
}
2222
}
2323
}

main/src/kotlinx/team/infra/api/ApiCheck.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,33 @@ fun Project.configureApiCheck(apiCheck: ApiCheckConfiguration) {
2727

2828
includeProjects.forEach { subproject ->
2929
// Checking for MPP beforeEvaluate is too early, and in afterEvaluate too late because node plugin breaks
30-
subproject.pluginManager.withPlugin("kotlin-multiplatform") { plugin ->
30+
subproject.pluginManager.withPlugin("kotlin-multiplatform") {
3131
val multiplatform = multiplatformClass?.let { subproject.extensions.findByType(it) }
3232
if (multiplatform == null) {
3333
logger.infra("Skipping apiCheck configuration for $subproject because multiplatform plugin has not been configured properly")
3434
return@withPlugin
3535
}
3636

3737
val apiCheckTask = subproject.tasks.create("checkApi") {
38-
it.group = "verification"
39-
it.description = "Runs API checks for 'main' compilations of all targets"
38+
group = "verification"
39+
description = "Runs API checks for 'main' compilations of all targets"
4040
}
4141

4242
val apiPublishTask = subproject.tasks.create("publishApiToBuildLocal") {
43-
it.group = "publishing"
44-
it.description = "Publishes API for 'main' compilations of all targets into local build folder"
43+
group = "publishing"
44+
description = "Publishes API for 'main' compilations of all targets into local build folder"
4545
}
4646
tasks.findByName("publishToBuildLocal")?.dependsOn(apiPublishTask)
4747

4848
val apiSyncTask = subproject.tasks.create("syncApi") {
49-
it.group = "other"
50-
it.description = "Syncs API for 'main' compilations of all targets"
49+
group = "other"
50+
description = "Syncs API for 'main' compilations of all targets"
5151
}
5252

5353
subproject.tasks.getByName("check").dependsOn(apiCheckTask)
5454

55-
multiplatform.targets.all { target ->
55+
multiplatform.targets.all {
56+
val target = this
5657
subproject.configureTargetApiCheck(target, apiCheckTask, apiSyncTask, apiPublishTask, apiCheck)
5758
}
5859
}

main/src/kotlinx/team/infra/api/DirectoryCompareTask.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ open class DirectoryCompareTask : DefaultTask() {
3333
val actualFiles = mutableSetOf<RelativePath>()
3434
val expectedFiles = mutableSetOf<RelativePath>()
3535
logger.infra("Comparing $expectedDir and $actualDir")
36-
project.fileTree(actualDir).visit { file ->
37-
actualFiles.add(file.relativePath)
36+
project.fileTree(actualDir).visit {
37+
actualFiles.add(this.relativePath)
3838
}
39-
project.fileTree(expectedDir).visit { file ->
40-
expectedFiles.add(file.relativePath)
39+
project.fileTree(expectedDir).visit {
40+
expectedFiles.add(this.relativePath)
4141
}
4242

4343
val missingFiles = expectedFiles - actualFiles

settings.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
pluginManagement {
22
repositories {
33
mavenCentral()
4-
maven { url 'https://plugins.gradle.org/m2/' }
4+
gradlePluginPortal()
5+
}
6+
plugins {
7+
id 'org.jetbrains.kotlin.jvm' version kotlin_version
58
}
69
}
710
rootProject.name = 'kotlinx.team.infra'

0 commit comments

Comments
 (0)