Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading Kotlin and Gradle #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions build.gradle

This file was deleted.

133 changes: 133 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension
import java.net.URI
import java.nio.file.Files
import java.nio.file.Path
import java.util.Properties

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:${project.extra["kotlinVersion"]}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.extra["kotlinVersion"]}")
}
}

plugins {
id("maven-publish")
id("java-gradle-plugin")
}
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "kotlin-sam-with-receiver")

// Load `local.properties` file, if it exists. You can put your spaceUser and spaceToken values there, that file is ignored by git
val localPropertiesFile = File("$project.rootDir/local.properties")
if (Files.exists(localPropertiesFile.toPath())) {
localPropertiesFile.reader().use { reader ->
val localProperties = Properties()
localProperties.load(reader)
localProperties.forEach { (key, value) -> project.ext.set(key.toString(), value) }
}
}

repositories {
mavenCentral()
gradlePluginPortal()
}

configure<GradlePluginDevelopmentExtension> {
plugins {
create("teamInfraPlugin") {
id = "kotlinx.team.infra"
implementationClass = "kotlinx.team.infra.InfraPlugin"
}
}
}

sourceSets {
getByName("main") {
java.srcDirs("main/src")
resources.srcDirs("main/resources")
}
getByName("test") {
java.srcDirs("test/src")
resources.srcDirs("test/resources")
}
}

configure<SamWithReceiverExtension> {
annotation("org.gradle.api.HasImplicitReceiver")
}

project.version = project.findProperty("releaseVersion") ?: project.version

tasks.register<Jar>("sourceJar") {
archiveClassifier.set("sources")
from(sourceSets.main.get().java.sourceDirectories)
}

configure<PublishingExtension> {
repositories {
maven {
name = "build"
url = Path.of(rootProject.layout.buildDirectory.get().asFile.path, "maven").toUri()
}
maven {
name = "space"
url = URI.create("https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven")
credentials {
username = project.findProperty("space.user") as? String
password = project.findProperty("space.token") as? String
}
}
}

publications.configureEach {
if (this is MavenPublication) artifact(tasks["sourceJar"])
}
}

afterEvaluate {
tasks {
named<Delete>("clean") {
publishing.repositories.forEach { repository ->
if (repository is MavenArtifactRepository && repository.name == "build") {
delete.add(repository.url)
}
}
}

create("publishToBuildRepository") {
group = "publishing"
withType(PublishToMavenRepository::class.java) {
if (repository.name == "build") {
[email protected](this)
}
}
}
}
}

dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib")
api("org.jetbrains.kotlin:kotlin-stdlib-jdk7")
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

compileOnly("org.jetbrains.kotlin:kotlin-compiler")
compileOnly("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:${project.extra["kotlinVersion"]}")

implementation("org.semver4j:semver4j:5.2.2")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13.2")
}

if (project.hasProperty("teamcity")) {
gradle.taskGraph.whenReady {
tasks.forEach { task ->
task.doFirst { println("##teamcity[progressMessage 'Gradle: ${project.path}:${task.name}']") }
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ kotlin.code.style=official
version = 0.4.0
group = kotlinx.team

kotlin_version=1.5.0
kotlinVersion=1.9.21
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionSha256Sum=29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
32 changes: 19 additions & 13 deletions main/src/kotlinx/team/infra/InfraPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package kotlinx.team.infra

import org.gradle.api.*
import org.gradle.util.*
import org.jetbrains.kotlin.gradle.plugin.*
import java.io.*
import java.nio.file.*
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
import org.semver4j.Semver
import java.io.FileInputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*

private const val REQUIRED_GRADLE_VERSION = "7.0"
private const val REQUIRED_KOTLIN_VERSION = "1.8.0"
private const val INFRA_EXTENSION_NAME = "infra"

@Suppress("unused")
class InfraPlugin : Plugin<Project> {
private val requiredGradleVersion = "6.0"
private val requiredKotlinVersion = "1.4.0"
private val INFRA_EXTENSION_NAME = "infra"

override fun apply(target: Project) = target.run {
verifyGradleVersion()
Expand Down Expand Up @@ -81,16 +86,17 @@ class InfraPlugin : Plugin<Project> {
tryGetClass<KotlinBasePluginWrapper>("org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper")
if (kotlinClass != null) {
plugins.findPlugin(kotlinClass)?.run {
logger.infra("Detected Kotlin plugin version '$kotlinPluginVersion'")
if (VersionNumber.parse(kotlinPluginVersion) < VersionNumber.parse(requiredKotlinVersion))
throw KotlinInfrastructureException("JetBrains Kotlin Infrastructure plugin requires Kotlin version $requiredKotlinVersion or higher")
logger.infra("Detected Kotlin plugin version '$pluginVersion'")
if (Semver(pluginVersion) < Semver(REQUIRED_KOTLIN_VERSION))
throw KotlinInfrastructureException("JetBrains Kotlin Infrastructure plugin requires Kotlin version $REQUIRED_KOTLIN_VERSION or higher")
}
}
}

@Suppress("UnusedReceiverParameter")
private fun Project.verifyGradleVersion() {
if (GradleVersion.current() < GradleVersion.version(requiredGradleVersion))
throw KotlinInfrastructureException("JetBrains Kotlin Infrastructure plugin requires Gradle version $requiredGradleVersion or higher")
if (GradleVersion.current() < GradleVersion.version(REQUIRED_GRADLE_VERSION))
throw KotlinInfrastructureException("JetBrains Kotlin Infrastructure plugin requires Gradle version $REQUIRED_GRADLE_VERSION or higher")
}
}

Expand Down
16 changes: 10 additions & 6 deletions main/src/kotlinx/team/infra/NativeMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ abstract class NativeInfraExtension(
commonMainSourceSet: KotlinSourceSet,
commonTestSourceSet: KotlinSourceSet,
) {
protected val mainSourceSet = kotlin.sourceSets.maybeCreate("${sourceSetName}Main").apply { dependsOn(commonMainSourceSet) }
protected val testSourceSet = kotlin.sourceSets.maybeCreate("${sourceSetName}Test").apply { dependsOn(commonTestSourceSet) }
protected val mainSourceSet: KotlinSourceSet = kotlin.sourceSets
.maybeCreate("${sourceSetName}Main")
.apply { dependsOn(commonMainSourceSet) }
protected val testSourceSet: KotlinSourceSet = kotlin.sourceSets
.maybeCreate("${sourceSetName}Test")
.apply { dependsOn(commonTestSourceSet) }

protected val sharedConfigs = mutableListOf<KotlinNativeTarget.() -> Unit>()
fun shared(configure: Closure<*>) = shared { ConfigureUtil.configure(configure, this) }
fun shared(configure: Closure<*>) = shared { project.configure(this, configure) }
fun shared(configure: KotlinNativeTarget.() -> Unit) {
sharedConfigs.add(configure)
}

fun target(name: String) = target(name) { }
fun target(name: String, configure: Closure<*>) = target(name) { ConfigureUtil.configure(configure, this) }
fun target(name: String, configure: Closure<*>) = target(name) { project.configure(this, configure) }
abstract fun target(name: String, configure: KotlinNativeTarget.() -> Unit)

fun common(name: String, configure: Closure<*>) = common(name) { ConfigureUtil.configure(configure, this) }
fun common(name: String, configure: Closure<*>) = common(name) { project.configure(this, configure) }
abstract fun common(name: String, configure: NativeInfraExtension.() -> Unit)
}

Expand Down Expand Up @@ -130,7 +134,7 @@ class NativeBuildInfraExtension(
val preset = nativePresets.singleOrNull { it.name == name } ?: return
project.logger.infra("Creating target '${preset.name}' with dependency on '$sourceSetName'")

val target = kotlin.targetFromPreset(preset) {
kotlin.targetFromPreset(preset) {
configure()
sharedConfigs.forEach { config -> config() }
}
Expand Down
Loading