Skip to content

Commit

Permalink
chore: support for kotlin 2.x
Browse files Browse the repository at this point in the history
- chore: changes to support kotlin `2.x`
- chore: changes to support newer serialization plugin
- chore: upgrade gradle → `8.6`
- chore: upgrade detekt → latest

Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Feb 14, 2024
1 parent 06add47 commit ee4712b
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 29 deletions.
14 changes: 14 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(libs.plugin.kotlin)
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
9 changes: 9 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "build-logic"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@file:Suppress("DSL_SCOPE_VIOLATION")

import org.gradle.accessors.dm.LibrariesForLibs
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val libs = the<LibrariesForLibs>()

plugins {
id("org.jetbrains.kotlin.jvm")
}

val ktTarget = KotlinVersion.KOTLIN_2_0

val ktCompilerArgs = listOf(
"-Xskip-prerelease-check",
"-Xsuppress-version-warnings",
"-Xallow-unstable-dependencies",
"-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
)

kotlin {
compilerOptions {
apiVersion = ktTarget
languageVersion = ktTarget
freeCompilerArgs = freeCompilerArgs.get().plus(ktCompilerArgs)
}
}

afterEvaluate {
tasks.withType(KotlinCompile::class).configureEach {
kotlinOptions {
apiVersion = ktTarget.version
languageVersion = ktTarget.version
freeCompilerArgs = freeCompilerArgs.plus(ktCompilerArgs)
}
}
}
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

plugins {
`maven-publish`

alias(libs.plugins.detekt)
alias(libs.plugins.diktat)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.versions)
id("org.jetbrains.reflekt.conventions")
}

group = "org.jetbrains.reflekt"
Expand Down
6 changes: 3 additions & 3 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ group = rootProject.group
version = rootProject.version

plugins {
id("org.jetbrains.reflekt") version "1.9.22"
kotlin("jvm") version "1.9.22"
id("org.jetbrains.reflekt") version "2.0.0-Beta4"
kotlin("jvm") version "2.0.0-Beta4"
}

allprojects {
Expand All @@ -28,7 +28,7 @@ allprojects {
}

dependencies {
implementation("org.jetbrains.reflekt", "reflekt-dsl", "1.9.22")
implementation("org.jetbrains.reflekt", "reflekt-dsl", "2.0.0-Beta4")
}

repositories {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
kotlin.code.style=official
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
org.gradle.caching=true
org.gradle.parallel=true
16 changes: 10 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
# - two places in the main README.md file (after releasing)
#
# Also, you should change the version in two places in the build.gradle.kts file in the example project
kotlin = "1.9.22"
kotlin = "2.0.0-Beta4"

detekt = "1.23.1"
detekt = "1.23.5"
dokka = "1.9.10"
diktat = "1.2.5"
junit-jupiter = "5.10.0"
junit-platform = "1.10.0"
kotlinpoet = "1.13.2"
junit-jupiter = "5.10.2"
junit-platform = "1.10.2"
kotlinpoet = "1.16.0"
kotlinx-serialization-protobuf = "1.6.2"
reflections = "0.10.2"
tomlj = "1.1.0"
tomlj = "1.1.1"
zip4j = "2.11.5"
plugin-publish = "1.2.1"
versions-check = "0.51.0"

[libraries]
gradle-plugin-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
gradle-plugin-diktat = { module = "org.cqfn.diktat:diktat-gradle-plugin", version.ref = "diktat" }
# -------Plugins-------
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
# -------Tests-------
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
Expand All @@ -46,3 +49,4 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
plugin-publish = { id = "com.gradle.plugin-publish", version.ref = "plugin-publish" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions-check" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
1 change: 1 addition & 0 deletions reflekt-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("org.jetbrains.reflekt.conventions")
alias(libs.plugins.kotlin.plugin.serialization)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.protobuf.ProtoBuf
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.*
import org.jetbrains.kotlin.ir.util.classId
Expand All @@ -26,6 +27,7 @@ object SerializationUtils {
return decoded.toLibraryArgumentsWithInstances(pluginContext)
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrTypeArgument.toSerializableIrTypeArgument(): SerializableIrTypeArgument {
if (this is IrStarProjection) {
return SerializableIrTypeArgument(
Expand All @@ -46,7 +48,6 @@ object SerializationUtils {
return this.toSerializableIrType()
}

@OptIn(ObsoleteDescriptorBasedAPI::class)
fun IrSimpleType.toSerializableIrType(): SerializableIrType {
val classifierClassId = this.classOrNull?.owner?.classId ?: error("Can not get class ID for type")
val arguments = arguments.map { it.toSerializableIrTypeArgument() }
Expand All @@ -69,8 +70,6 @@ object SerializationUtils {
it.arguments = this.arguments.map { argument -> argument.toIrTypeArgument(pluginContext) }
// TODO: should we deserialize it?
it.abbreviation = null

it.variance = this.variance
}.buildSimpleType()

private fun SerializableIrTypeArgument.toIrTypeArgument(pluginContext: IrPluginContext): IrTypeArgument {
Expand All @@ -79,6 +78,6 @@ object SerializationUtils {
}
return IrSimpleTypeBuilder().also {
it.classifier = pluginContext.referenceClass(requireNotNull(this.classId) { "Empty classId for IrTypeProjection" })
}.buildTypeProjection()
}.buildTypeProjection(this.variance)
}
}
11 changes: 7 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
rootProject.name = "reflekt"

include(":reflekt-plugin")

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

rootProject.name = "reflekt"

includeBuild("build-logic")
include(":reflekt-plugin")
includeBuild("using-embedded-kotlin")

enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
2 changes: 1 addition & 1 deletion using-embedded-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ subprojects {
localDirectory = this@subprojects.file("src/main/kotlin")

remoteUrl =
URL("https://github.com/JetBrains-Research/reflekt/tree/master/using-embedded-kotlin/${this@subprojects.name}/src/main/kotlin/")
uri("https://github.com/JetBrains-Research/reflekt/tree/master/using-embedded-kotlin/${this@subprojects.name}/src/main/kotlin/").toURL()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions using-embedded-kotlin/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("org.jetbrains.reflekt.conventions")
kotlin("plugin.serialization") version embeddedKotlinVersion
alias(libs.plugins.plugin.publish)
}
Expand Down
4 changes: 4 additions & 0 deletions using-embedded-kotlin/reflekt-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id("org.jetbrains.reflekt.conventions")
}

group = rootProject.group
version = rootProject.version

Expand Down
4 changes: 4 additions & 0 deletions using-embedded-kotlin/reflekt-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id("org.jetbrains.reflekt.conventions")
}

group = rootProject.group
version = rootProject.version

Expand Down

0 comments on commit ee4712b

Please sign in to comment.