Skip to content

Commit

Permalink
Chore(infra): Prepare atomicfu for including to the Kotlin Aggregate …
Browse files Browse the repository at this point in the history
…build //KTI-1016

Parametrize kotlin api version, kotlin language version.

Support passing an url for a kotlin compiler repository, drop space kotlin/dev repo from dependencies:
Kotlin compiler artifacts should be downloaded from maven central by default.
In case of compiling with not-published into the MC kotlin compiler artifacts, a kotlin_repo_url should be specified as a gradle parameter(E.g. space kotlin/dev repo).
  • Loading branch information
stasjas committed Dec 6, 2022
1 parent 89a8859 commit 9c93c31
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
4 changes: 2 additions & 2 deletions atomicfu-gradle-plugin/build.gradle
Expand Up @@ -14,8 +14,8 @@ if (rootProject.ext.jvm_ir_enabled) {
// Gradle plugin must be compiled targeting the same Kotlin version as used by Gradle
kotlin.sourceSets.all {
languageSettings {
apiVersion = "1.4"
languageVersion = "1.4"
apiVersion = KotlinAggregateBuild.getKotlinApiVersion(project) ?: "1.4"
languageVersion = KotlinAggregateBuild.getKotlinLanguageVersion(project) ?: "1.4"
}
}

Expand Down
11 changes: 7 additions & 4 deletions atomicfu-maven-plugin/build.gradle
Expand Up @@ -23,6 +23,8 @@ def buildSnapshots = rootProject.properties['build_snapshot_train'] != null

evaluationDependsOn(':atomicfu-transformer')

def kotlinDevRepoUrl = KotlinAggregateBuild.getKotlinDevRepositoryUrl(project) as String

task generatePomFile(dependsOn: [compileKotlin, ':atomicfu-transformer:publishToMavenLocal']) {
def buildDir = project.buildDir // because Maven model also has "project"
outputs.file(pomFile)
Expand All @@ -43,11 +45,12 @@ task generatePomFile(dependsOn: [compileKotlin, ':atomicfu-transformer:publishTo
appendNode('project.build.sourceEncoding', 'UTF-8')
}
appendNode('repositories').with {
appendNode('repository').with {
appendNode('id', 'dev')
appendNode('url', 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev')
if (kotlinDevRepoUrl != "") {
appendNode('repository').with {
appendNode('id', 'dev')
appendNode('url', kotlinDevRepoUrl)
}
}

if (buildSnapshots) {
appendNode('repository').with {
appendNode('id', 'kotlin-snapshots')
Expand Down
25 changes: 16 additions & 9 deletions build.gradle
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.kotlin.konan.target.HostManager

buildscript {


/*
* These property group is used to build kotlinx.atomicfu against Kotlin compiler snapshot.
* How does it work:
Expand All @@ -29,14 +31,16 @@ buildscript {
ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null

def kotlinDevRepoUrl = KotlinAggregateBuild.getKotlinDevRepositoryUrl(project) as String

repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
// Future replacement for kotlin-dev, with cache redirector
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
if (kotlinDevRepoUrl != "") {
maven { url kotlinDevRepoUrl }
}
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Expand All @@ -54,12 +58,15 @@ allprojects {
}
}

println "Using Kotlin $kotlin_version for project $it"
logger.info("Using Kotlin compiler $kotlin_version for $it")

def kotlinDevRepoUrl = KotlinAggregateBuild.getKotlinDevRepositoryUrl(project) as String

repositories {
mavenCentral()
// Future replacement for kotlin-dev, with cache redirector
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
if (kotlinDevRepoUrl!= "") {
maven { url kotlinDevRepoUrl }
}
}

def deployVersion = properties['DeployVersion']
Expand All @@ -79,7 +86,7 @@ allprojects {
}
}

println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
logger.info("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
if (build_snapshot_train) {
afterEvaluate {
println "Manifest of kotlin-compiler-embeddable.jar for atomicfu"
Expand Down
42 changes: 42 additions & 0 deletions buildSrc/src/main/kotlin/KotlinAggregateBuild.kt
@@ -0,0 +1,42 @@
@file:JvmName("KotlinAggregateBuild")

import org.gradle.api.Project
import java.util.logging.Logger

val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")

/*
* Should be used for running against of non-released Kotlin compiler on a system test level
* @return a Kotlin API version parametrized from command line nor gradle.properties, null otherwise
* */
fun getKotlinApiVersion(project: Project): String? {
val apiVersion = project.rootProject.properties["kotlin_api_version"] as? String
if (apiVersion != null)
LOGGER.info("""Configured Kotlin API version: '$apiVersion' for project $${project.name}""")
return apiVersion
}

/*
* Should be used for running against of non-released Kotlin compiler on a system test level
* @return a Kotlin Language version parametrized from command line nor gradle.properties, null otherwise
* */
fun getKotlinLanguageVersion(project: Project): String? {
val languageVersion = project.rootProject.properties["kotlin_language_version"] as? String
if (languageVersion != null)
LOGGER.info("""Configured Kotlin Language version: '$languageVersion' for project ${project.name}""")
return languageVersion
}

/*
* Should be used for running against of non-released Kotlin compiler on a system test level
* Kotlin compiler artifacts are expected to be downloaded from maven central by default.
* In case of compiling with not-published into the MC kotlin compiler artifacts, a kotlin_repo_url gradle parameter should be specified.
* To reproduce a build locally, a kotlin/dev repo should be passed
* @return an url for a kotlin compiler repository parametrized from command line nor gradle.properties, empty string otherwise
* */
fun getKotlinDevRepositoryUrl(project: Project): String {
val url = (project.rootProject.properties["kotlin_repo_url"] ?: "") as String
if (url != "")
LOGGER.info("""Configured Kotlin Compiler repository url: '$url' for project ${project.name}""")
return url
}
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -6,6 +6,7 @@ version=0.18.5-SNAPSHOT
group=org.jetbrains.kotlinx

kotlin_version=1.7.20

asm_version=9.3
slf4j_version=1.8.0-alpha2
junit_version=4.12
Expand Down
5 changes: 2 additions & 3 deletions gradle/compile-options.gradle
@@ -1,4 +1,3 @@

/*
* Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand All @@ -19,8 +18,8 @@ ext.configureKotlin = { isMultiplatform ->

kotlin.sourceSets.all {
languageSettings {
apiVersion = "1.4"
languageVersion = "1.4"
apiVersion = KotlinAggregateBuild.getKotlinApiVersion(project) ?: "1.4"
languageVersion = KotlinAggregateBuild.getKotlinLanguageVersion(project) ?: "1.4"
}
}
}

0 comments on commit 9c93c31

Please sign in to comment.