Simplify Kotlin bootstrap application in the project

Move all the code to apply Kotlin bootstrap into settings script plugin
which does following:
- configures based either on the repo root 'local.properties' or on the
root project gradle properties or on the repo root 'gradle.properties'
current type of bootstrap
- automatically adds Kotlin bootstrap repository with
exclusive content, so bootstrap dependencies will not be by mistake
downloaded from other repository
- automatically forces all Kotlin plugins applied in the build to use
bootstrap version

This script should be applied only in project settings.gradle and then
it does all the configuration by itself.
This commit is contained in:
Yahor Berdnikau
2022-10-24 16:42:51 +02:00
committed by Space Team
parent 97b68d111c
commit a14d0d148b
29 changed files with 392 additions and 321 deletions
+2 -25
View File
@@ -3,17 +3,6 @@ import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
buildscript {
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
repositories {
bootstrapKotlinRepo?.let(::maven)
mavenCentral()
gradlePluginPortal()
}
// a workaround for kotlin compiler classpath in kotlin project: sometimes gradle substitutes
// kotlin-stdlib external dependency with local project :kotlin-stdlib in kotlinCompilerClasspath configuration.
// see also configureCompilerClasspath@
@@ -23,8 +12,6 @@ buildscript {
bootstrapCompilerClasspath(kotlin("compiler-embeddable", bootstrapKotlinVersion))
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
classpath(kotlin("gradle-plugin", bootstrapKotlinVersion))
classpath(kotlin("serialization", bootstrapKotlinVersion))
}
val versionPropertiesFile = project.rootProject.projectDir.resolve("gradle/versions.properties")
@@ -50,6 +37,8 @@ plugins {
id("org.gradle.crypto.checksum") version "1.2.0"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.0" apply false
signing
id("org.jetbrains.kotlin.jvm") apply false
id("org.jetbrains.kotlin.plugin.serialization") apply false
}
pill {
@@ -502,18 +491,6 @@ allprojects {
mirrorRepo?.let(::maven)
internalBootstrapRepo?.let(::maven)?.apply {
content {
includeGroup("org.jetbrains.kotlin")
}
}
bootstrapKotlinRepo?.let(::maven)?.apply {
content {
includeGroup("org.jetbrains.kotlin")
}
}
maven(intellijRepo)
maven("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies")
+7 -26
View File
@@ -1,28 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
// workaround for KGP build metrics reports: https://github.com/gradle/gradle/issues/20001
project.extensions.extraProperties["kotlin.build.report.output"] = null
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:${project.bootstrapKotlinVersion}")
}
val versionPropertiesFile = project.rootProject.projectDir.parentFile.resolve("gradle/versions.properties")
val versionProperties = java.util.Properties()
versionPropertiesFile.inputStream().use { propInput ->
@@ -43,16 +24,15 @@ logger.info("buildSrc kotlin compiler version: " + org.jetbrains.kotlin.config.K
logger.info("buildSrc stdlib version: " + KotlinVersion.CURRENT)
apply {
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
plugin("groovy")
from("../gradle/checkCacheability.gradle.kts")
}
plugins {
`kotlin-dsl`
`java-gradle-plugin`
`groovy`
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
}
gradlePlugin {
@@ -159,16 +139,17 @@ java {
dependencies {
implementation(kotlin("stdlib", embeddedKotlinVersion))
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
implementation("com.gradle.publish:plugin-publish-plugin:1.0.0")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.7.0")
implementation("com.jakewharton.dex:dex-member-list:4.1.1")
implementation("gradle.plugin.com.github.johnrengelman:shadow:${rootProject.extra["versions.shadow"]}")
implementation("gradle.plugin.com.github.johnrengelman:shadow:${rootProject.extra["versions.shadow"]}") {
// https://github.com/johnrengelman/shadow/issues/807
exclude("org.ow2.asm")
}
implementation("net.sf.proguard:proguard-gradle:6.2.2")
implementation("org.jetbrains.intellij.deps:asm-all:8.0.1")
implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.0.1")
+1
View File
@@ -1,5 +1,6 @@
pluginManagement {
apply from: '../repo/scripts/cache-redirector.settings.gradle.kts'
apply from: '../repo/scripts/kotlin-bootstrap.settings.gradle.kts'
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
-14
View File
@@ -26,20 +26,6 @@ val Project.intellijRepo
else -> "https://www.jetbrains.com/intellij-repository/releases"
}
val Project.internalBootstrapRepo: String?
get() =
when {
bootstrapKotlinRepo?.startsWith("https://buildserver.labs.intellij.net") == true
|| bootstrapKotlinRepo?.startsWith("https://teamcity.jetbrains.com") == true ->
bootstrapKotlinRepo!!.replace("artifacts/content/maven", "artifacts/content/internal/repo")
project.kotlinBuildProperties.isJpsBuildEnabled ->
"https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Aggregate)," +
"number:$bootstrapKotlinVersion,branch:default:any/artifacts/content/internal/repo/"
else -> null
}
fun Project.commonDependency(coordinates: String): String {
val parts = coordinates.split(':')
return when (parts.size) {
@@ -16,93 +16,3 @@ var Project.bootstrapKotlinRepo: String?
private set(value) {
extensions.extraProperties.set("bootstrapKotlinRepo", value)
}
fun Project.kotlinBootstrapFrom(defaultSource: BootstrapOption) {
val teamCityBootstrapVersion = kotlinBuildProperties.teamCityBootstrapVersion
val customBootstrapVersion = kotlinBuildProperties.customBootstrapVersion
val bootstrapSource = when {
kotlinBuildProperties.localBootstrap -> BootstrapOption.Local(
kotlinBuildProperties.localBootstrapVersion,
kotlinBuildProperties.localBootstrapPath
)
teamCityBootstrapVersion != null -> BootstrapOption.TeamCity(
teamCityBootstrapVersion,
kotlinBuildProperties.teamCityBootstrapBuildNumber,
projectExtId = kotlinBuildProperties.teamCityBootstrapProject,
teamcityUrl = kotlinBuildProperties.teamCityBootstrapUrl,
onlySuccessBootstrap = false
)
customBootstrapVersion != null -> BootstrapOption.Custom(
kotlinVersion = customBootstrapVersion,
repo = kotlinBuildProperties.customBootstrapRepo
)
else -> defaultSource
}
bootstrapSource.applyToProject(this)
logger.lifecycle("Using kotlin bootstrap version $bootstrapKotlinVersion from repo $bootstrapKotlinRepo")
}
sealed class BootstrapOption {
abstract fun applyToProject(project: Project)
/** Manual repository and version specification.
*
* If [repo] is not specified the default buildscript and project repositories are used
*/
open class Custom(val kotlinVersion: String, val repo: String?, val cacheRedirector: Boolean = false) : BootstrapOption() {
override fun applyToProject(project: Project) {
project.bootstrapKotlinVersion = kotlinVersion
project.bootstrapKotlinRepo = if (cacheRedirector)
repo?.let { URI(it) }?.let { "https://cache-redirector.jetbrains.com/${it.host}/${it.path}" }
else
repo
}
}
/** Get bootstrap from kotlin bootstrap space repo, where bootstraps are published */
class SpaceBootstrap(kotlinVersion: String, cacheRedirector: Boolean = false) :
Custom(kotlinVersion, "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap", cacheRedirector)
/** Get bootstrap from teamcity maven artifacts of the specified build configuration
*
* [kotlinVersion] the version of maven artifacts
* [buildNumber] build number of a teamcity build, by default the same as [kotlinVersion],
* [projectExtId] extId of a teamcity build configuration, by default "Kotlin_dev_Compiler",
* [onlySuccessBootstrap] allow artifacts only from success builds of the default branch tagged with 'bootstrap' tag
*/
class TeamCity(
val kotlinVersion: String,
val buildNumber: String? = null,
val projectExtId: String? = null,
val onlySuccessBootstrap: Boolean = true,
val teamcityUrl: String? = null
) : BootstrapOption() {
override fun applyToProject(project: Project) {
val query = if (onlySuccessBootstrap) "status:SUCCESS,tag:bootstrap,pinned:true" else "branch:default:any"
project.bootstrapKotlinRepo =
"${teamcityUrl ?: "https://buildserver.labs.intellij.net"}/guestAuth/app/rest/builds/buildType:(id:${projectExtId
?: "Kotlin_KotlinDev_Compiler"}),number:${buildNumber ?: kotlinVersion},$query/artifacts/content/maven/"
project.bootstrapKotlinVersion = kotlinVersion
}
}
/**
* Use previously published local artifacts from the build/repo maven repository
*
* [kotlinVersion] version of artifacts, by default the snapshot version of project is used
* [localPath] the path to local repository, if specified it is resolved with respect or project dir
*/
class Local(val kotlinVersion: String? = null, val localPath: String? = null) : BootstrapOption() {
override fun applyToProject(project: Project) {
val rootProjectDir = project.kotlinBuildProperties.rootProjectDir
val repoPath = if (localPath != null)
rootProjectDir.resolve(localPath).canonicalFile
else
rootProjectDir.resolve("build").resolve("repo")
project.bootstrapKotlinRepo = repoPath.toURI().toString()
project.bootstrapKotlinVersion = kotlinVersion ?: project.property("defaultSnapshotVersion") as String
}
}
}
+1 -10
View File
@@ -12,26 +12,17 @@ plugins {
groovy
`kotlin-dsl`
id("gradle-plugin-dependency-configuration")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
}
buildscript {
val rootBuildDirectory by extra(project.file("../.."))
repositories {
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
apply(from = rootBuildDirectory.resolve("kotlin-native/gradle/loadRootProperties.gradle"))
dependencies {
classpath(commonDependency("com.google.code.gson:gson"))
classpath("org.jetbrains.kotlin:kotlin-sam-with-receiver:${project.bootstrapKotlinVersion}")
}
}
apply {
plugin("kotlin-sam-with-receiver")
}
val rootProperties = Properties().apply {
project(":kotlin-native").projectDir.resolve("gradle.properties").reader().use(::load)
@@ -1,11 +1,5 @@
import org.jetbrains.kotlin.UtilsKt
project.buildscript.repositories {
maven {
url BootstrapKt.getBootstrapKotlinRepo(project)
}
mavenCentral()
}
def kotlinRoot = ext.properties.containsKey("rootBuildDirectory") ? file("${ext.rootBuildDirectory}/..") : rootProject.projectDir
File versionPropertiesFile = new File(kotlinRoot, "gradle/versions.properties")
def versionProperties = new Properties()
@@ -22,10 +16,6 @@ project.buildscript.configurations.all {
}
}
project.buildscript.dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}"
}
configurations {
kotlinCompilerClasspath
}
@@ -1,8 +1,5 @@
buildscript {
apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle"
repositories {
mavenCentral()
}
}
def rootBuildDirectory = rootProject.projectDir
+4 -12
View File
@@ -23,16 +23,16 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
repositories {
maven{ url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
}
}
plugins {
id("org.jetbrains.kotlin.multiplatform") apply false
}
def globalProperties = new java.util.Properties()
ext.kotlin_root = project.file("../..").absolutePath
project.logger.info("kotlin_root: $kotlin_root")
@@ -81,16 +81,8 @@ subprojects { proj ->
if (deploySnapshotStr != "default.snapshot") deploySnapshotStr else defaultSnapshotVersion
} ?: proj.ext["buildNumber"]
proj.buildscript.repositories {
maven {
url proj.ext["bootstrapKotlinRepo"]
}
}
proj.repositories {
mavenCentral()
maven {
url proj.ext["bootstrapKotlinRepo"]
}
}
}
@@ -14,39 +14,23 @@ buildscript {
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() ?: false
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
}
}
apply{
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
}
plugins {
`kotlin-dsl`
//kotlin("multiplatform") version "${project.bootstrapKotlinVersion}"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
//kotlin("multiplatform")
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
gradlePluginPortal()
extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
}
tasks.validatePlugins.configure {
@@ -1,5 +1,8 @@
import java.io.File
pluginManagement {
apply(from = "../../../repo/scripts/cache-redirector.settings.gradle.kts")
apply(from = "../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
@@ -6,8 +6,6 @@ import org.gradle.api.Project
fun Project.kotlinInit(cacheRedirectorEnabled: Boolean) {
extensions.extraProperties["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
extensions.extraProperties["kotlinVersion"] = findProperty("kotlinVersion")
extensions.extraProperties["konanVersion"] = findProperty("konanVersion")
}
+10
View File
@@ -2,6 +2,16 @@
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
pluginManagement {
apply from: '../../repo/scripts/cache-redirector.settings.gradle.kts'
apply from: '../../repo/scripts/kotlin-bootstrap.settings.gradle.kts'
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
gradlePluginPortal()
}
}
include ':ring'
include ':cinterop'
@@ -21,25 +21,16 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
}
plugins {
id("org.jetbrains.kotlin.multiplatform")
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
maven {
url project.bootstrapKotlinRepo
}
mavenCentral()
}
def getHostName() {
def target = System.getProperty("os.name")
if (target == 'Linux') return 'linux'
@@ -11,44 +11,26 @@ buildscript {
extra[key] = value
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() ?: false
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
extra["bootstrapKotlinRepo"] = project.bootstrapKotlinRepo
extra["bootstrapKotlinVersion"] = project.bootstrapKotlinVersion
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
}
}
apply{
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
}
plugins {
`kotlin-dsl`
//kotlin("multiplatform") version "${project.bootstrapKotlinVersion}"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
//kotlin("multiplatform")
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
gradlePluginPortal()
extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
}
tasks.validatePlugins.configure {
@@ -1,4 +1,7 @@
pluginManagement {
apply(from = "../../../../repo/scripts/cache-redirector.settings.gradle.kts")
apply(from = "../../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
@@ -0,0 +1,10 @@
pluginManagement {
apply(from = "../../../repo/scripts/cache-redirector.settings.gradle.kts")
apply(from = "../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
gradlePluginPortal()
}
}
@@ -20,26 +20,14 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
}
plugins {
id("org.jetbrains.kotlin.multiplatform")
}
repositories {
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
}
kotlin {
@@ -11,43 +11,26 @@ buildscript {
extra[key] = value
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() ?: false
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
extra["bootstrapKotlinRepo"] = project.bootstrapKotlinRepo
extra["bootstrapKotlinVersion"] = project.bootstrapKotlinVersion
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
}
}
apply{
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
}
plugins {
`kotlin-dsl`
//kotlin("multiplatform") version "${project.bootstrapKotlinVersion}"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
//kotlin("multiplatform")
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
gradlePluginPortal()
extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
mavenCentral()
}
@@ -55,7 +38,6 @@ tasks.validatePlugins.configure {
enabled = false
}
sourceSets["main"].withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class) {
kotlin.filter.exclude("**/FileCheckTest.kt")
kotlin.filter.exclude("**/bitcode/**")
@@ -1,4 +1,7 @@
pluginManagement {
apply(from = "../../../../repo/scripts/cache-redirector.settings.gradle.kts")
apply(from = "../../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
@@ -0,0 +1,10 @@
pluginManagement {
apply from: '../../../repo/scripts/cache-redirector.settings.gradle.kts'
apply from: '../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts'
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
gradlePluginPortal()
}
}
@@ -22,27 +22,16 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
repositories {
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
plugins {
id("org.jetbrains.kotlin.multiplatform")
}
repositories {
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
}
apply plugin: 'kotlin-multiplatform'
kotlin {
js(IR) {
@@ -11,49 +11,31 @@ buildscript {
extra[key] = value
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() ?: false
extra["defaultSnapshotVersion"] = kotlinBuildProperties.defaultSnapshotVersion
kotlinBootstrapFrom(BootstrapOption.SpaceBootstrap(kotlinBuildProperties.kotlinBootstrapVersion!!, cacheRedirectorEnabled))
extra["bootstrapKotlinRepo"] = project.bootstrapKotlinRepo
extra["bootstrapKotlinVersion"] = project.bootstrapKotlinVersion
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
project.bootstrapKotlinRepo?.let {
maven(url = it)
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
}
}
apply{
plugin("kotlin")
plugin("kotlin-sam-with-receiver")
}
plugins {
`kotlin-dsl`
//kotlin("multiplatform") version "${project.bootstrapKotlinVersion}"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
//kotlin("multiplatform")
}
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
repositories {
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
gradlePluginPortal()
extra["bootstrapKotlinRepo"]?.let {
maven(url = it)
}
}
tasks.validatePlugins.configure {
enabled = false
}
sourceSets["main"].withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class) {
kotlin.filter.exclude("**/FileCheckTest.kt")
kotlin.filter.exclude("**/bitcode/**")
@@ -1,4 +1,7 @@
pluginManagement {
apply(from = "../../../../../repo/scripts/cache-redirector.settings.gradle.kts")
apply(from = "../../../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven {
url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
@@ -0,0 +1,10 @@
pluginManagement {
apply from: '../../../../repo/scripts/cache-redirector.settings.gradle.kts'
apply from: '../../../../repo/scripts/kotlin-bootstrap.settings.gradle.kts'
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
gradlePluginPortal()
}
}
+1
View File
@@ -3,3 +3,4 @@
This directory contains the scripts that should be applied before even settings evaluation
and cannot be convention plugins:
- [script](cache-redirector.settings.gradle.kts) to redirect all repositories to cache redirector service
- [script](kotlin-bootstrap.settings.gradle.kts) to apply Kotlin bootstrap settings
@@ -0,0 +1,302 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// Apply this settings script in the project settings.gradle following way:
// pluginManagement {
// apply from: 'kotlin-bootstrap.settings.gradle.kts'
// }
import java.util.Properties
import org.gradle.api.internal.GradleInternal
object Config {
const val LOCAL_BOOTSTRAP = "bootstrap.local"
const val LOCAL_BOOTSTRAP_VERSION = "bootstrap.local.version"
const val LOCAL_BOOTSTRAP_PATH = "bootstrap.local.path"
const val TEAMCITY_BOOTSTRAP_VERSION = "bootstrap.teamcity.kotlin.version"
const val TEAMCITY_BOOTSTRAP_BUILD_NUMBER = "bootstrap.teamcity.build.number"
const val TEAMCITY_BOOTSTRAP_PROJECT = "bootstrap.teamcity.project"
const val TEAMCITY_BOOTSTRAP_URL = "bootstrap.teamcity.url"
const val CUSTOM_BOOTSTRAP_VERSION = "bootstrap.kotlin.version"
const val CUSTOM_BOOTSTRAP_REPO = "bootstrap.kotlin.repo"
const val DEFAULT_SNAPSHOT_VERSION = "defaultSnapshotVersion"
const val DEFAULT_BOOTSTRAP_VERSION = "bootstrap.kotlin.default.version"
const val PROJECT_KOTLIN_VERSION = "bootstrapKotlinVersion"
const val PROJECT_KOTLIN_REPO = "bootstrapKotlinRepo"
const val IS_JPS_BUILD_ENABLED = "jpsBuild"
}
abstract class PropertiesValueSource : ValueSource<Properties, PropertiesValueSource.Parameters> {
interface Parameters : ValueSourceParameters {
val fileName: Property<String>
val rootDir: Property<File>
}
override fun obtain(): Properties? {
val localPropertiesFile = parameters.rootDir.get().resolve(parameters.fileName.get())
return if (localPropertiesFile.exists()) {
localPropertiesFile.bufferedReader().use {
Properties().apply { load(it) }
}
} else {
null
}
}
}
fun getRootSettings(
settings: Settings,
gradle: Gradle
): Settings {
// Gradle interface neither exposes flag if it is a root of composite-build hierarchy
// nor gives access to Settings object. Fortunately it is availaibe inside GradleInternal internal api
// used by build scan plugin.
val gradleInternal = (gradle as GradleInternal)
return if (gradleInternal.isRootBuild()) {
settings
} else {
val gradleParent = gradle.parent ?: error("Could not get includedBuild parent build for ${settings.rootDir}!")
getRootSettings(gradle.parent!!.settings, gradle.parent!!)
}
}
val rootSettings = getRootSettings(settings, settings.gradle)
// Workaround for the case when included build could be run directly via --project-dir option.
// In this case `rootSettings.rootDir` will point to --project-dir location rather then Kotlin repo real root.
// So in such case script falls back to manual mapping
val kotlinRootDir: File = when (rootSettings.rootProject.name) {
"buildSrc" -> {
val parentDir = rootSettings.rootDir.parentFile
when (parentDir.name) {
"benchmarksAnalyzer", "performance-server" -> parentDir.parentFile.parentFile.parentFile
"performance" -> parentDir.parentFile.parentFile
"ui" -> parentDir.parentFile.parentFile.parentFile.parentFile
else -> parentDir
}
}
"benchmarksAnalyzer", "performance-server" -> rootSettings.rootDir.parentFile.parentFile.parentFile
"performance" -> rootSettings.rootDir.parentFile.parentFile
"ui" -> rootSettings.rootDir.parentFile.parentFile.parentFile.parentFile
else -> rootSettings.rootDir
}
private val localProperties = providers.of(PropertiesValueSource::class.java) {
parameters {
fileName.set("local.properties")
rootDir.set(kotlinRootDir)
}
}.forUseAtConfigurationTime()
private val rootGradleProperties = providers.of(PropertiesValueSource::class.java) {
parameters {
fileName.set("gradle.properties")
rootDir.set(kotlinRootDir)
}
}.forUseAtConfigurationTime()
fun loadLocalOrGradleProperty(
propertyName: String
): Provider<String> {
// Workaround for https://github.com/gradle/gradle/issues/19114
// as in the includedBuild GradleProperties are empty on configuration cache reuse
return if ((gradle as GradleInternal).isRootBuild()) {
localProperties.map { it.getProperty(propertyName) }.forUseAtConfigurationTime()
.orElse(providers.gradleProperty(propertyName).forUseAtConfigurationTime())
.orElse(rootGradleProperties.map { it.getProperty(propertyName) }.forUseAtConfigurationTime())
} else {
localProperties.map { it.getProperty(propertyName) }.forUseAtConfigurationTime()
.orElse(rootSettings.providers.gradleProperty(propertyName).forUseAtConfigurationTime())
.orElse(rootGradleProperties.map { it.getProperty(propertyName) }.forUseAtConfigurationTime())
}
}
fun Project.logBootstrapApplied(message: String) {
if (this == rootProject) logger.lifecycle(message) else logger.info(message)
}
fun String?.propValueToBoolean(default: Boolean = false): Boolean {
return when {
this == null -> default
isEmpty() -> true // has property without value means 'true'
else -> trim().toBoolean()
}
}
fun Provider<String>.mapToBoolean(): Provider<Boolean> = map { it?.propValueToBoolean() }
fun RepositoryHandler.addBootstrapRepo(
bootstrapRepo: String,
bootstrapVersion: String,
additionalBootstrapRepos: List<String> = emptyList()
) {
exclusiveContent {
forRepositories(
*(listOf(bootstrapRepo) + additionalBootstrapRepos)
.map {
maven { url = uri(it) }
}
.toTypedArray()
)
filter {
// kotlin-build-gradle-plugin and non bootstrap-versions
// should be excluded from strict content filtering
includeVersionByRegex(
"org\\.jetbrains\\.kotlin",
"^(?!kotlin-build-gradle-plugin).*$",
bootstrapVersion.toRegex().pattern
)
// Kotlin Gradle plugins that have slightly separate maven coordinates
includeVersionByRegex(
"org\\.jetbrains\\.kotlin\\..*$",
"org\\.jetbrains\\.kotlin\\..*\\.gradle\\.plugin$",
bootstrapVersion.toRegex().pattern
)
}
}
}
@OptIn(kotlin.ExperimentalStdlibApi::class)
fun getAdditionalBootstrapRepos(
bootstrapRepo: String,
bootstrapKotlinVersion: String,
isJpsBuildEnabled: Boolean
): List<String> {
return buildList {
if (bootstrapRepo.startsWith("https://buildserver.labs.intellij.net")
|| bootstrapRepo.startsWith("https://teamcity.jetbrains.com")) {
add(bootstrapRepo.replace("artifacts/content/maven", "artifacts/content/internal/repo"))
}
if (isJpsBuildEnabled) {
add(
"https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Aggregate)," +
"number:$bootstrapKotlinVersion,branch:default:any/artifacts/content/internal/repo/"
)
}
}
}
fun Settings.applyBootstrapConfiguration(
bootstrapVersion: String,
bootstrapRepo: String,
isJpsBuildEnabled: Boolean,
logMessage: String
) {
settings.pluginManagement.repositories.addBootstrapRepo(bootstrapRepo, bootstrapVersion)
settings.pluginManagement.resolutionStrategy.eachPlugin {
if (requested.id.id.startsWith("org.jetbrains.kotlin.")) {
useVersion(bootstrapVersion)
}
}
val additionalRepos = getAdditionalBootstrapRepos(bootstrapRepo, bootstrapVersion, isJpsBuildEnabled)
gradle.beforeProject {
bootstrapKotlinVersion = bootstrapVersion
bootstrapKotlinRepo = bootstrapRepo
repositories.addBootstrapRepo(bootstrapRepo, bootstrapVersion, additionalRepos)
logBootstrapApplied(logMessage)
}
}
val isLocalBootstrapEnabled: Provider<Boolean> = loadLocalOrGradleProperty(Config.LOCAL_BOOTSTRAP)
.mapToBoolean().orElse(false).forUseAtConfigurationTime()
val localBootstrapVersion: Provider<String> = loadLocalOrGradleProperty(Config.LOCAL_BOOTSTRAP_VERSION)
.orElse(loadLocalOrGradleProperty(Config.DEFAULT_SNAPSHOT_VERSION))
val localBootstrapPath: Provider<String> = loadLocalOrGradleProperty(Config.LOCAL_BOOTSTRAP_PATH)
val teamCityBootstrapVersion = loadLocalOrGradleProperty(Config.TEAMCITY_BOOTSTRAP_VERSION)
val teamCityBootstrapBuildNumber = loadLocalOrGradleProperty(Config.TEAMCITY_BOOTSTRAP_BUILD_NUMBER)
val teamCityBootstrapProject = loadLocalOrGradleProperty(Config.TEAMCITY_BOOTSTRAP_PROJECT)
val teamCityBootstrapUrl = loadLocalOrGradleProperty(Config.TEAMCITY_BOOTSTRAP_URL)
val customBootstrapVersion = loadLocalOrGradleProperty(Config.CUSTOM_BOOTSTRAP_VERSION)
val customBootstrapRepo = loadLocalOrGradleProperty(Config.CUSTOM_BOOTSTRAP_REPO)
val defaultBootstrapVersion = loadLocalOrGradleProperty(Config.DEFAULT_BOOTSTRAP_VERSION)
val isJpsBuildEnabled = loadLocalOrGradleProperty(Config.IS_JPS_BUILD_ENABLED)
.mapToBoolean().orElse(false).forUseAtConfigurationTime()
var Project.bootstrapKotlinVersion: String
get() = property(Config.PROJECT_KOTLIN_VERSION) as String
set(value) {
extensions.extraProperties.set(Config.PROJECT_KOTLIN_VERSION, value)
}
var Project.bootstrapKotlinRepo: String?
get() = property(Config.PROJECT_KOTLIN_REPO) as String?
set(value) {
extensions.extraProperties.set(Config.PROJECT_KOTLIN_REPO, value)
}
// Get bootstrap kotlin version and repository url
// and set it using pluginManagement and dependencyManangement
when {
isLocalBootstrapEnabled.get() -> {
val bootstrapVersion = localBootstrapVersion.get()
val localPath = localBootstrapPath.orNull
val rootDirectory = rootSettings.rootDir
val repoPath = if (localPath != null) {
rootDirectory.resolve(localPath).canonicalFile
} else {
rootDirectory.resolve("build").resolve("repo")
}
val bootstrapRepo = repoPath.toURI().toString()
applyBootstrapConfiguration(
bootstrapVersion,
bootstrapRepo,
isJpsBuildEnabled.get(),
"Using Kotlin local bootstrap version $bootstrapVersion from $bootstrapRepo"
)
}
teamCityBootstrapVersion.orNull != null -> {
val bootstrapVersion = teamCityBootstrapVersion.get()
val query = "branch:default:any"
val baseRepoUrl = teamCityBootstrapUrl.orNull ?: "https://buildserver.labs.intellij.net"
val teamCityProjectId = teamCityBootstrapProject.orNull ?: "Kotlin_KotlinDev_Compiler"
val teamCityBuildNumber = teamCityBootstrapBuildNumber.orNull ?: bootstrapVersion
val bootstrapRepo = "$baseRepoUrl/guestAuth/app/rest/builds/buildType:(id:$teamCityProjectId),number:$teamCityBuildNumber,$query/artifacts/content/maven/"
applyBootstrapConfiguration(
bootstrapVersion,
bootstrapRepo,
isJpsBuildEnabled.get(),
"Using Kotlin TeamCity bootstrap version $bootstrapVersion from $bootstrapRepo"
)
}
customBootstrapVersion.orNull != null -> {
val bootstrapVersion = customBootstrapVersion.get()
val bootstrapRepo = customBootstrapRepo.get()
applyBootstrapConfiguration(
bootstrapVersion,
bootstrapRepo,
isJpsBuildEnabled.get(),
"Using Kotlin custom bootstrap version $bootstrapVersion from $bootstrapRepo"
)
}
else -> {
val bootstrapVersion = defaultBootstrapVersion.get()
val bootstrapRepo = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap"
applyBootstrapConfiguration(
bootstrapVersion,
bootstrapRepo,
isJpsBuildEnabled.get(),
"Using Kotlin Space bootstrap version $bootstrapVersion from $bootstrapRepo"
)
}
}
+1 -6
View File
@@ -1,13 +1,8 @@
pluginManagement {
apply from: 'repo/scripts/cache-redirector.settings.gradle.kts'
apply from: 'repo/scripts/kotlin-bootstrap.settings.gradle.kts'
repositories {
def pluginRepo = System.getProperty("bootstrap.kotlin.repo")
if (pluginRepo != null) {
maven {
url pluginRepo
}
}
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
gradlePluginPortal()