Skip to content

Commit 99f29a6

Browse files
committed
Update the project structure to work with kotlin-master
1 parent e5cd71b commit 99f29a6

30 files changed

+97
-59
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Ignore Gradle build output directory
55
build
66
.kotlin
7-
7+
lib-kotlin
88
# idea files
99
.idea/*
1010
!.idea/runConfigurations

gradle-conventions-settings/build.gradle.kts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@ configurations.configureEach {
1515
}
1616
}
1717

18-
val isLatestKotlinVersion: Boolean by extra
19-
2018
dependencies {
21-
api(libs.kotlin.gradle.plugin)
22-
api(libs.detekt.gradle.plugin)
23-
api(libs.binary.compatibility.validator.gradle.plugin)
24-
25-
if (isLatestKotlinVersion) {
26-
api(libs.kover.gradle.plugin)
27-
}
28-
2919
// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
3020
api(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
3121
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.api.plugins.ExtensionAware
8+
import org.gradle.kotlin.dsl.extra
9+
import org.gradle.kotlin.dsl.provideDelegate
10+
11+
12+
enum class ActionApplied {
13+
Applied, NotApplied;
14+
}
15+
16+
@Suppress("unused")
17+
inline fun ExtensionAware.whenKotlinIsAtLeast(
18+
major: Int,
19+
minor: Int,
20+
patch: Int = 0,
21+
action: () -> Unit = {},
22+
): ActionApplied {
23+
val kotlinVersion: KotlinVersion by extra
24+
25+
if (kotlinVersion.isAtLeast(major, minor, patch)) {
26+
action()
27+
28+
return ActionApplied.Applied
29+
}
30+
31+
return ActionApplied.NotApplied
32+
}
33+
34+
inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied {
35+
val isLatestKotlinVersion: Boolean by extra
36+
37+
if (isLatestKotlinVersion) {
38+
action()
39+
return ActionApplied.Applied
40+
}
41+
42+
return ActionApplied.NotApplied
43+
}
44+
45+
infix fun ActionApplied.otherwise(body: () -> Unit) {
46+
if (this == ActionApplied.NotApplied) {
47+
body()
48+
}
49+
}

gradle-conventions/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ plugins {
1010
alias(libs.plugins.gradle.kotlin.dsl)
1111
}
1212

13-
// chicken-egg
14-
apply(from = "src/main/kotlin/compiler-specific-module.gradle.kts")
15-
1613
defaultConventionConfiguration()
1714

1815
dependencies {
16+
implementation(project(":common"))
1917
implementation(":gradle-conventions-settings")
2018

2119
project.whenKotlinLatest {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import util.defaultConventionConfiguration
6+
7+
plugins {
8+
alias(libs.plugins.gradle.kotlin.dsl)
9+
}
10+
11+
defaultConventionConfiguration()
12+
13+
val isLatestKotlinVersion: Boolean by extra
14+
15+
dependencies {
16+
implementation(":gradle-conventions-settings")
17+
18+
api(libs.kotlin.gradle.plugin)
19+
api(libs.detekt.gradle.plugin)
20+
api(libs.binary.compatibility.validator.gradle.plugin)
21+
22+
if (isLatestKotlinVersion) {
23+
api(libs.kover.gradle.plugin)
24+
}
25+
26+
// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
27+
api(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
28+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
// empty

gradle-conventions-settings/src/main/kotlin/util/KotlinVersion.kt renamed to gradle-conventions/common/src/main/kotlin/util/KotlinVersion.kt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package util
66

7-
import org.gradle.api.plugins.ExtensionAware
8-
import org.gradle.kotlin.dsl.extra
97
import org.gradle.kotlin.dsl.provideDelegate
108
import java.io.File
119
import java.nio.file.Files
@@ -87,39 +85,3 @@ private fun Collection<File>.mostSpecificByVersionOrNull(kotlinVersion: KotlinVe
8785
// - pre_1_9_20
8886
// etc.
8987
private val directoryNameRegex = "^(latest|(v|pre)(_\\d){1,3}\\d?)$".toRegex()
90-
91-
data class ActionApplied(val applied: Boolean)
92-
93-
@Suppress("unused")
94-
inline fun ExtensionAware.whenKotlinIsAtLeast(
95-
major: Int,
96-
minor: Int,
97-
patch: Int = 0,
98-
action: () -> Unit = {},
99-
): ActionApplied {
100-
val kotlinVersion: KotlinVersion by extra
101-
102-
if (kotlinVersion.isAtLeast(major, minor, patch)) {
103-
action()
104-
105-
return ActionApplied(true)
106-
}
107-
108-
return ActionApplied(false)
109-
}
110-
111-
inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied {
112-
val isLatestKotlinVersion: Boolean by extra
113-
114-
if (isLatestKotlinVersion) {
115-
action()
116-
}
117-
118-
return ActionApplied(isLatestKotlinVersion)
119-
}
120-
121-
infix fun ActionApplied.otherwise(body: () -> Unit) {
122-
if (!applied) {
123-
body()
124-
}
125-
}

gradle-conventions-settings/src/main/kotlin/util/forIde.kt renamed to gradle-conventions/common/src/main/kotlin/util/forIde.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fun Project.whenForIde(block: () -> Unit): ActionApplied {
1111

1212
if (forIdeBuild) {
1313
block()
14+
return ActionApplied.Applied
1415
}
1516

16-
return ActionApplied(forIdeBuild)
17+
return ActionApplied.NotApplied
1718
}

gradle-conventions/empty/build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import util.filterDirectory
6-
import util.name
5+
import java.io.File
76
import java.nio.file.Files
87
import java.nio.file.Path
98

109
plugins {
1110
alias(libs.plugins.gradle.kotlin.dsl)
1211
}
1312

13+
fun Path.name() = fileName?.toString().orEmpty()
14+
15+
fun filterDirectory(sourceSetPath: Path, filter: (Path) -> Boolean): List<File> {
16+
return Files.newDirectoryStream(sourceSetPath).use { it.toList() }.filter(filter).map { it.toFile() }
17+
}
18+
1419
val pluginsSource: Path = layout.projectDirectory.dir("../latest-only/src/main/kotlin").asFile.toPath()
1520

1621
val plugins = filterDirectory(pluginsSource) {

gradle-conventions/latest-only/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ plugins {
1111
defaultConventionConfiguration()
1212

1313
dependencies {
14+
implementation(project(":common"))
15+
1416
implementation(":gradle-conventions-settings")
1517
implementation(libs.kotlin.gradle.plugin)
1618
implementation(libs.kover.gradle.plugin)

gradle-conventions/settings.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import util.otherwise
66
import util.whenKotlinLatest
77

8-
/*
9-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
10-
*/
11-
128
rootProject.name = "gradle-conventions"
139

1410
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
@@ -24,6 +20,8 @@ plugins {
2420
id("conventions-version-resolution")
2521
}
2622

23+
include(":common")
24+
2725
whenKotlinLatest {
2826
include(":latest-only")
2927
} otherwise {

0 commit comments

Comments
 (0)