Skip to content

Commit

Permalink
Update the project structure to work with kotlin-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Nov 21, 2024
1 parent e5cd71b commit 99f29a6
Show file tree
Hide file tree
Showing 30 changed files with 97 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Ignore Gradle build output directory
build
.kotlin

lib-kotlin
# idea files
.idea/*
!.idea/runConfigurations
Expand Down
10 changes: 0 additions & 10 deletions gradle-conventions-settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ configurations.configureEach {
}
}

val isLatestKotlinVersion: Boolean by extra

dependencies {
api(libs.kotlin.gradle.plugin)
api(libs.detekt.gradle.plugin)
api(libs.binary.compatibility.validator.gradle.plugin)

if (isLatestKotlinVersion) {
api(libs.kover.gradle.plugin)
}

// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
api(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.provideDelegate


enum class ActionApplied {
Applied, NotApplied;
}

@Suppress("unused")
inline fun ExtensionAware.whenKotlinIsAtLeast(
major: Int,
minor: Int,
patch: Int = 0,
action: () -> Unit = {},
): ActionApplied {
val kotlinVersion: KotlinVersion by extra

if (kotlinVersion.isAtLeast(major, minor, patch)) {
action()

return ActionApplied.Applied
}

return ActionApplied.NotApplied
}

inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied {
val isLatestKotlinVersion: Boolean by extra

if (isLatestKotlinVersion) {
action()
return ActionApplied.Applied
}

return ActionApplied.NotApplied
}

infix fun ActionApplied.otherwise(body: () -> Unit) {
if (this == ActionApplied.NotApplied) {
body()
}
}
4 changes: 1 addition & 3 deletions gradle-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ plugins {
alias(libs.plugins.gradle.kotlin.dsl)
}

// chicken-egg
apply(from = "src/main/kotlin/compiler-specific-module.gradle.kts")

defaultConventionConfiguration()

dependencies {
implementation(project(":common"))
implementation(":gradle-conventions-settings")

project.whenKotlinLatest {
Expand Down
28 changes: 28 additions & 0 deletions gradle-conventions/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import util.defaultConventionConfiguration

plugins {
alias(libs.plugins.gradle.kotlin.dsl)
}

defaultConventionConfiguration()

val isLatestKotlinVersion: Boolean by extra

dependencies {
implementation(":gradle-conventions-settings")

api(libs.kotlin.gradle.plugin)
api(libs.detekt.gradle.plugin)
api(libs.binary.compatibility.validator.gradle.plugin)

if (isLatestKotlinVersion) {
api(libs.kover.gradle.plugin)
}

// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
api(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

// empty
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package util

import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.provideDelegate
import java.io.File
import java.nio.file.Files
Expand Down Expand Up @@ -87,39 +85,3 @@ private fun Collection<File>.mostSpecificByVersionOrNull(kotlinVersion: KotlinVe
// - pre_1_9_20
// etc.
private val directoryNameRegex = "^(latest|(v|pre)(_\\d){1,3}\\d?)$".toRegex()

data class ActionApplied(val applied: Boolean)

@Suppress("unused")
inline fun ExtensionAware.whenKotlinIsAtLeast(
major: Int,
minor: Int,
patch: Int = 0,
action: () -> Unit = {},
): ActionApplied {
val kotlinVersion: KotlinVersion by extra

if (kotlinVersion.isAtLeast(major, minor, patch)) {
action()

return ActionApplied(true)
}

return ActionApplied(false)
}

inline fun ExtensionAware.whenKotlinLatest(action: () -> Unit): ActionApplied {
val isLatestKotlinVersion: Boolean by extra

if (isLatestKotlinVersion) {
action()
}

return ActionApplied(isLatestKotlinVersion)
}

infix fun ActionApplied.otherwise(body: () -> Unit) {
if (!applied) {
body()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fun Project.whenForIde(block: () -> Unit): ActionApplied {

if (forIdeBuild) {
block()
return ActionApplied.Applied
}

return ActionApplied(forIdeBuild)
return ActionApplied.NotApplied
}
9 changes: 7 additions & 2 deletions gradle-conventions/empty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import util.filterDirectory
import util.name
import java.io.File
import java.nio.file.Files
import java.nio.file.Path

plugins {
alias(libs.plugins.gradle.kotlin.dsl)
}

fun Path.name() = fileName?.toString().orEmpty()

fun filterDirectory(sourceSetPath: Path, filter: (Path) -> Boolean): List<File> {
return Files.newDirectoryStream(sourceSetPath).use { it.toList() }.filter(filter).map { it.toFile() }
}

val pluginsSource: Path = layout.projectDirectory.dir("../latest-only/src/main/kotlin").asFile.toPath()

val plugins = filterDirectory(pluginsSource) {
Expand Down
2 changes: 2 additions & 0 deletions gradle-conventions/latest-only/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ plugins {
defaultConventionConfiguration()

dependencies {
implementation(project(":common"))

implementation(":gradle-conventions-settings")
implementation(libs.kotlin.gradle.plugin)
implementation(libs.kover.gradle.plugin)
Expand Down
6 changes: 2 additions & 4 deletions gradle-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import util.otherwise
import util.whenKotlinLatest

/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

rootProject.name = "gradle-conventions"

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
Expand All @@ -24,6 +20,8 @@ plugins {
id("conventions-version-resolution")
}

include(":common")

whenKotlinLatest {
include(":latest-only")
} otherwise {
Expand Down

0 comments on commit 99f29a6

Please sign in to comment.