Skip to content
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
13 changes: 6 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import org.jetbrains.kotlin.gradle.dsl.*
import org.gradle.kotlin.dsl.*

buildscript {
if (shouldUseLocalMaven(rootProject)) {
repositories {
mavenLocal()
}
}

repositories {
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
Expand Down Expand Up @@ -64,6 +58,7 @@ allprojects {
apply(plugin = "base")
apply(plugin = "kover-conventions")

val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
// Configure repositories
allprojects {
repositories {
Expand All @@ -72,7 +67,11 @@ allprojects {
* transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
*/
google()
mavenCentral()
if (cacheRedirectorEnabled) {
maven("https://cache-redirector.jetbrains.com/maven-central")
} else {
mavenCentral()
}
addDevRepositoryIfEnabled(this, project)
}
}
Expand Down
17 changes: 13 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ plugins {
val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
val buildSnapshotTrain = properties["build_snapshot_train"]?.toString()?.toBoolean() == true
val kotlinDevUrl = project.providers.gradleProperty("kotlin_repo_url").orNull
val kotlinVersion = project.providers.gradleProperty("kotlin_version").orNull

repositories {
mavenCentral()
if (cacheRedirectorEnabled) {
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2")
maven("https://cache-redirector.jetbrains.com/maven-central")
} else {
maven("https://plugins.gradle.org/m2")
mavenCentral()
}
if (!kotlinDevUrl.isNullOrEmpty()) {
maven(kotlinDevUrl)
if (!kotlinDevUrl.isNullOrEmpty() && !kotlinVersion.isNullOrEmpty()) {
exclusiveContent {
forRepository {
maven(kotlinDevUrl)
}
filter {
includeVersionByRegex("org.jetbrains.kotlin", ".*", kotlinVersion)
}
}
}
if (buildSnapshotTrain) {
mavenLocal()
Expand All @@ -35,7 +44,7 @@ fun version(target: String): String {
}
val version = "${target}_version"
// Read from CLI first, used in aggregate builds
return properties[version]?.let{"$it"} ?: gradleProperties.getProperty(version)
return properties[version]?.let { "$it" } ?: gradleProperties.getProperty(version)
}

kotlin {
Expand Down
19 changes: 18 additions & 1 deletion buildSrc/src/main/kotlin/CommunityProjectsBuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,24 @@ fun getKotlinDevRepositoryUrl(project: Project): String? {
*/
fun addDevRepositoryIfEnabled(rh: RepositoryHandler, project: Project) {
val devRepoUrl = getKotlinDevRepositoryUrl(project) ?: return
rh.maven(devRepoUrl)
val version = getKotlinDevVersion(project) ?: return
rh.exclusiveContent {
forRepository {
rh.maven(devRepoUrl)
}
filter {
includeVersionByRegex("org.jetbrains.kotlin", ".*", version)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Badya, Why it has to be done this way?

@Badya Badya Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best way to use in such a case, and Gradle best practice.
https://docs.gradle.org/current/userguide/filtering_repository_content.html#sec:declaring-content-repositories

Looking up dev deps in central or in cache redirector (which is gonna poll central under the hood) will result in guaranteed 404, but also will count towards central's request limit bringing up potential throttling and 429 Too Many Requests.
By using this Gradle is guaranteed not to look up deps matching regexp elsewhere.

Additionally I suspect Gradle to continue trying other repositories on 404 but in the case of 429 Too Many Requests from central, it just fails the build right away. Provided solution also prevents this behavior regardless of repos declaring order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to simply move the dev repo declaration before central repo and gradle plugins portal?

@Badya Badya Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the dev repo declaration before

If something is wrong with dev repo and gradle fails to find artifacts there, it still gonna try other repos in that case, which we want to avoid, since we know for 100% artifacts are not there.

This is the best way to configure gradle for this case

@fzhinkin fzhinkin Jun 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the dev repo is specified in cases when we know for sure that the artifact should be there, isn't it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my view, this configuration makes perfect sense. The kotlin_dev_repo Gradle property specifies: "You must use the Kotlin development repository for Kotlin!" That means we aren't supposed to use the non-development repository for Kotlin. The proposed config catches the error where 1) kotlinx.coroutines accidentally depends on a hardcoded version of Kotlin, or 2) where the TeamCity config got broken and passed a stable instead of the development version of Kotlin, or 3) where the Kotlin Gradle Plugin got broken and accidentally stripped out the dev version suffix during resolution... It's a reasonable way of ensuring we get exactly what we requested, instead of pulling in something undesired from Maven without noticing.

}
}
}

fun getKotlinDevVersion(project: Project): String? {
val version = project.providers.gradleProperty("kotlin_version").orNull
if (version != null) {
LOGGER.info("""Configured Kotlin Compiler version: '$version' for project ${project.name}""")
return version
}
return null
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=f1771298a70f6db5a29daf62378c4e18a17fc33c9ba6b14362e0cdf40610380d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
distributionUrl=https\://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-8.14.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
16 changes: 12 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ pluginManagement {

repositories {
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/")
gradlePluginPortal()
val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
if (cacheRedirectorEnabled) {
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2")
} else {
gradlePluginPortal()
}
val prop = System.getProperty("build_snapshot_train")
var build_snapshot_train: String by extra
build_snapshot_train = if (prop != null && prop != "") "true" else "false"
if (build_snapshot_train.toBoolean()) {
mavenLocal()
}
}
}

Expand All @@ -19,9 +30,6 @@ fun module(path: String) {
include(name)
project(":$name").projectDir = file(path)
}
val prop = System.getProperty("build_snapshot_train")
var build_snapshot_train: String by extra
build_snapshot_train = if (prop != null && prop != "") "true" else "false"
// ---------------------------

include("benchmarks")
Expand Down