Introduce repo settings conventions

First convention is to configure Gradle build cache.
This commit is contained in:
Yahor Berdnikau
2023-02-09 13:36:46 +01:00
committed by Space Team
parent 2405f28e64
commit b7f50aeaf2
8 changed files with 129 additions and 44 deletions
+11 -12
View File
@@ -1,6 +1,13 @@
import org.gradle.api.internal.GradleInternal
pluginManagement {
apply from: '../repo/scripts/cache-redirector.settings.gradle.kts'
apply from: '../repo/scripts/kotlin-bootstrap.settings.gradle.kts'
if (((GradleInternal) gradle).isRootBuild()) {
includeBuild '../repo/gradle-settings-conventions'
}
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
@@ -8,6 +15,10 @@ pluginManagement {
}
}
plugins {
id "build-cache"
}
File versionPropertiesFile = new File(rootProject.projectDir.parentFile, "gradle/versions.properties")
def versionProperties = new Properties()
versionPropertiesFile.withInputStream {
@@ -30,16 +41,4 @@ dependencyResolutionManagement {
}
}
buildscript {
repositories {
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies" }
mavenCentral()
}
def buildGradlePluginVersion = ext["kotlin.build.gradlePlugin.version"]
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:$buildGradlePluginVersion")
}
}
include "prepare-deps"
@@ -0,0 +1,7 @@
## Description
Provides common settings convention plugins for the repo.
### List of plugins
- "build-cache" - local and remote build cache configuration
@@ -0,0 +1,16 @@
plugins {
`kotlin-dsl`
id("org.jetbrains.kotlin.jvm")
}
repositories {
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
}
kotlin.jvmToolchain(8)
val buildGradlePluginVersion = extra.get("kotlin.build.gradlePlugin.version")
dependencies {
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:$buildGradlePluginVersion")
}
@@ -0,0 +1,24 @@
val buildProperties = getKotlinBuildPropertiesForSettings(settings)
buildCache {
local {
isEnabled = buildProperties.localBuildCacheEnabled
if (buildProperties.localBuildCacheDirectory != null) {
directory = buildProperties.localBuildCacheDirectory
}
}
val remoteBuildCacheUrl = buildProperties.buildCacheUrl
if (remoteBuildCacheUrl != null) {
remote<HttpBuildCache> {
url = uri(remoteBuildCacheUrl)
isPush = buildProperties.pushToBuildCache
if (buildProperties.buildCacheUser != null &&
buildProperties.buildCachePassword != null
) {
credentials.username = buildProperties.buildCacheUser
credentials.password = buildProperties.buildCachePassword
}
}
}
}
@@ -0,0 +1,3 @@
kotlin.build.gradlePlugin.version=0.0.39
kotlin.options.suppressFreeCompilerArgsModificationWarning=true
cacheRedirectorEnabled=true
@@ -0,0 +1,52 @@
pluginManagement {
apply(from = "../scripts/cache-redirector.settings.gradle.kts")
apply(from = "../scripts/kotlin-bootstrap.settings.gradle.kts")
repositories {
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
gradlePluginPortal()
}
}
buildscript {
repositories {
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
mavenCentral()
}
val buildGradlePluginVersion = extra.get("kotlin.build.gradlePlugin.version")
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:$buildGradlePluginVersion")
}
}
include(":build-cache")
// Unfortunately it is not possible to apply build-cache.settings.gradle.kts as script compilation
// could not then find types from "kotlin-build-gradle-plugin"
// Sync below to the content of settings plugin
val buildProperties = getKotlinBuildPropertiesForSettings(settings)
buildCache {
local {
isEnabled = buildProperties.localBuildCacheEnabled
if (buildProperties.localBuildCacheDirectory != null) {
directory = buildProperties.localBuildCacheDirectory
}
}
val remoteBuildCacheUrl = buildProperties.buildCacheUrl
if (remoteBuildCacheUrl != null) {
remote<HttpBuildCache> {
url = uri(remoteBuildCacheUrl)
isPush = buildProperties.pushToBuildCache
if (buildProperties.buildCacheUser != null &&
buildProperties.buildCachePassword != null
) {
credentials.username = buildProperties.buildCacheUser
credentials.password = buildProperties.buildCachePassword
}
}
}
}
@@ -58,12 +58,19 @@ fun getRootSettings(
// 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.
//
// Included builds for build logic are evaluated earlier then root settings leading to error that root settings object is not yet
// available. For such cases we fallback to included build settings object and later manual mapping for kotlinRootDir
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!!)
return when {
gradleInternal.isRootBuild() ||
settings.rootProject.name == "gradle-settings-conventions" -> {
settings
}
else -> {
val gradleParent = gradle.parent ?: error("Could not get includedBuild parent build for ${settings.rootDir}!")
getRootSettings(gradle.parent!!.settings, gradle.parent!!)
}
}
}
@@ -83,6 +90,7 @@ val kotlinRootDir: File = when (rootSettings.rootProject.name) {
}
}
"benchmarksAnalyzer", "performance-server" -> rootSettings.rootDir.parentFile.parentFile.parentFile
"gradle-settings-conventions" -> rootSettings.rootDir.parentFile.parentFile
"performance" -> rootSettings.rootDir.parentFile.parentFile
"ui" -> rootSettings.rootDir.parentFile.parentFile.parentFile.parentFile
else -> rootSettings.rootDir
+3 -27
View File
@@ -1,4 +1,6 @@
pluginManagement {
includeBuild("repo/gradle-settings-conventions")
apply from: 'repo/scripts/cache-redirector.settings.gradle.kts'
apply from: 'repo/scripts/kotlin-bootstrap.settings.gradle.kts'
@@ -13,17 +15,11 @@ pluginManagement {
}
}
buildscript {
def buildGradlePluginVersion = ext["kotlin.build.gradlePlugin.version"]
dependencies {
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${buildGradlePluginVersion}")
}
}
plugins {
id "com.gradle.enterprise" version "3.11.2"
id "com.gradle.common-custom-user-data-gradle-plugin" version "1.8.1" apply false
id "org.gradle.toolchains.foojay-resolver-convention" version "0.4.0"
id "build-cache"
}
def buildProperties = BuildPropertiesKt.getKotlinBuildPropertiesForSettings(settings)
@@ -54,26 +50,6 @@ gradleEnterprise {
}
}
buildCache {
local {
enabled = buildProperties.localBuildCacheEnabled
if (buildProperties.localBuildCacheDirectory != null) {
directory = buildProperties.localBuildCacheDirectory
}
}
if (buildProperties.buildCacheUrl != null) {
remote(HttpBuildCache) {
url = buildProperties.buildCacheUrl
push = buildProperties.pushToBuildCache
if (buildProperties.buildCacheUser != null && buildProperties.buildCachePassword != null) {
credentials.username = buildProperties.buildCacheUser
credentials.password = buildProperties.buildCachePassword
}
}
}
}
// modules
include ":benchmarks",
":compiler",