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

Use JetBrains cache-redirector #3650

Merged
merged 10 commits into from
Jun 27, 2024
20 changes: 15 additions & 5 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ rootProject.name = "build-logic"

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2") {
name = "GradlePluginPortal-JBCache"
}
}
includeBuild("../build-settings-logic")
}

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
google()
gradlePluginPortal()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/dl.google.com.android.maven2") {
name = "Google-JBCache"
}
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2") {
name = "GradlePluginPortal-JBCache"
}
}

versionCatalogs {
Expand Down
16 changes: 12 additions & 4 deletions build-settings-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ rootProject.name = "build-settings-logic"

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2") {
name = "GradlePluginPortal-JBCache"
}
}
}

@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode = PREFER_SETTINGS
repositories {
mavenCentral()
gradlePluginPortal()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2") {
name = "GradlePluginPortal-JBCache"
}
}

versionCatalogs {
Expand Down
71 changes: 51 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,43 @@ val gradlePluginIncludedBuilds = listOf("runner-gradle-plugin-classic")

addDependencyOnSameTasksOfIncludedBuilds("assemble", "build", "clean", "check")

registerParentGroupTasks("publishing", taskNames = listOf(
"publishAllPublicationsToMavenCentralRepository",
"publishAllPublicationsToProjectLocalRepository",
"publishAllPublicationsToSnapshotRepository",
"publishAllPublicationsToSpaceDevRepository",
"publishAllPublicationsToSpaceTestRepository",
"publishToMavenLocal"
)) {
registerParentGroupTasks(
"publishing", taskNames = listOf(
"publishAllPublicationsToMavenCentralRepository",
"publishAllPublicationsToProjectLocalRepository",
"publishAllPublicationsToSnapshotRepository",
"publishAllPublicationsToSpaceDevRepository",
"publishAllPublicationsToSpaceTestRepository",
"publishToMavenLocal"
)
) {
it.name in publishedIncludedBuilds
}

registerParentGroupTasks("gradle plugin", taskNames = listOf(
"publishPlugins",
"validatePlugins"
)) {
registerParentGroupTasks(
"gradle plugin", taskNames = listOf(
"publishPlugins",
"validatePlugins"
)
) {
it.name in gradlePluginIncludedBuilds
}

registerParentGroupTasks("bcv", taskNames = listOf(
"apiDump",
"apiCheck",
"apiBuild"
)) {
registerParentGroupTasks(
"bcv", taskNames = listOf(
"apiDump",
"apiCheck",
"apiBuild"
)
) {
it.name in publishedIncludedBuilds
}

registerParentGroupTasks("verification", taskNames = listOf(
"test"
))
registerParentGroupTasks(
"verification", taskNames = listOf(
"test"
)
)

tasks.register("integrationTest") {
group = "verification"
Expand Down Expand Up @@ -82,3 +90,26 @@ fun includedBuildTasks(taskName: String, filter: (IncludedBuild) -> Boolean = {
.filter { it.name != "build-logic" }
.filter(filter)
.mapNotNull { it.task(":$taskName") }


tasks.wrapper {
val gradleVersion = "8.7"
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to clarify: after PR merged to update the version of Gradle, we need:

  1. set gradleVersion to the new value
  2. go to https://gradle.org/release-checksums/ and copy the checksum
  3. set distributionSha256Sum to the new value
  4. run gradle wrapper

correct?

Previously it was just gradle wrapper --gradle-version=8.8

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I will double check and document the steps. Normally I update gradle.properties but yes, there are multiple ways.

Previously it was just gradle wrapper --gradle-version=8.8

And then re-run gradle wrapper, otherwise the wrapper scripts won't be updated 🙃

Copy link
Member Author

@adam-enko adam-enko Jun 20, 2024

Choose a reason for hiding this comment

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

TIL how to update Gradle (while using distributionSha256Sum). It is not simple :(

Hopefully the instructions are clear - WDYT?

distributionUrl =
"https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip"
// Checksums are available here: https://gradle.org/release-checksums/
distributionSha256Sum = "544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d"
doLast {
propertiesFile.writeText(
buildString {
appendLine("# DO NOT MODIFY THIS FILE")
appendLine("#")
appendLine("# To change the Gradle version modify the wrapper task in the root build.gradle.kts")
appendLine("#")
appendLine("# Explanation:")
appendLine("# Normally the easiest way to update Gradle is to edit gradle-wrapper.properties and re-run `gradle wrapper`.")
appendLine("# However, the wrapper task will overwrite the JetBrains cached URL unless it is specified in the task.")
append(propertiesFile.readText())
}
)
}
}
66 changes: 54 additions & 12 deletions dokka-integration-tests/maven/src/main/kotlin/settingsXml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ import java.nio.file.Paths

/** Create `settings.xml` file contents, with the custom dev Maven repos. */
@Language("xml")
public fun createSettingsXml(): String {
fun createSettingsXml(): String {
/** file-based Maven repositories with Dokka dependencies */
val devMavenRepositories: List<Path> by systemProperty { repos ->
repos.split(",").map { Paths.get(it) }
}

val pluginRepos = devMavenRepositories
.withIndex()
.joinToString("\n") { (i, repoPath) ->
/* language=xml */
"""
|<pluginRepository>
| <id>devMavenRepo${i}</id>
| <url>${repoPath.toUri().toASCIIString()}</url>
|</pluginRepository>
""".trimMargin()
}
val mavenCentralRepo = Repository(
id = "MavenCentral-JBCached",
url = "https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2",
)

val pluginRepos = buildList {
addAll(
devMavenRepositories.mapIndexed { i, repoPath ->
Repository(
id = "devMavenRepo${i}",
url = repoPath.toUri().toASCIIString()
)
}
)
add(mavenCentralRepo)
}.joinToString("\n") { it.pluginRepository() }

return """
|<settings>
Expand All @@ -38,12 +43,49 @@ public fun createSettingsXml(): String {
| <pluginRepositories>
|${pluginRepos.prependIndent(" ")}
| </pluginRepositories>
| <repositories>
|${mavenCentralRepo.repository().prependIndent(" ")}
| </repositories>
| </profile>
| </profiles>
| <mirrors>
|${mavenCentralRepo.mirror(of = "central").prependIndent(" ")}
| </mirrors>
| <activeProfiles>
| <activeProfile>maven-dev</activeProfile>
| </activeProfiles>
|</settings>
|
""".trimMargin()
}

private data class Repository(
val id: String,
@Language("http-url-reference")
val url: String,
) {
@Language("XML")
fun repository() = """
<repository>
<id>${id}</id>
<url>${url}</url>
</repository>
""".trimIndent()

@Language("XML")
fun pluginRepository() = """
<pluginRepository>
<id>${id}</id>
<url>${url}</url>
</pluginRepository>
""".trimIndent()

@Language("XML")
fun mirror(of: String) = """
<mirror>
<id>${id}</id>
<url>${url}</url>
<mirrorOf>${of}</mirrorOf>
</mirror>
""".trimIndent()
}
10 changes: 7 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# DO NOT MODIFY THIS FILE
#
# Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
# To change the Gradle version modify the wrapper task in the root build.gradle.kts
#

# Explanation:
# Normally the easiest way to update Gradle is to edit gradle-wrapper.properties and re-run `gradle wrapper`.
# However, the wrapper task will overwrite the JetBrains cached URL unless it is specified in the task.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
37 changes: 27 additions & 10 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ pluginManagement {
includeBuild("build-settings-logic")

repositories {
mavenCentral()
gradlePluginPortal()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2") {
name = "GradlePluginPortal-JBCache"
}
}
}

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide")
maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide") {
name = "KotlinIde-JBCache"
}
maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies") {
name = "KotlinIdePluginDependencies-JBCache"
}

maven("https://cache-redirector.jetbrains.com/intellij-repository/releases")
maven("https://cache-redirector.jetbrains.com/intellij-third-party-dependencies")
maven("https://cache-redirector.jetbrains.com/intellij-repository/releases") {
name = "IjRepository-JBCache"
}
maven("https://cache-redirector.jetbrains.com/intellij-third-party-dependencies") {
name = "IjThirdParty-JBCache"
}

mavenCentral()
google()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2") {
name = "MavenCentral-JBCache"
}
maven("https://cache-redirector.jetbrains.com/dl.google.com.android.maven2") {
name = "Google-JBCache"
}

// Declare the Node.js & Yarn download repositories
//region Declare the Node.js & Yarn download repositories
// Required by Gradle Node plugin: https://github.com/node-gradle/gradle-node-plugin/blob/3.5.1/docs/faq.md#is-this-plugin-compatible-with-centralized-repositories-declaration
exclusiveContent {
forRepository {
Expand All @@ -42,7 +58,7 @@ dependencyResolutionManagement {

exclusiveContent {
forRepository {
ivy("https://github.com/yarnpkg/yarn/releases/download") {
ivy("https://cache-redirector.jetbrains.com/github.com/yarnpkg/yarn/releases/download") {
name = "Yarn Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
metadataSources { artifact() }
Expand All @@ -51,6 +67,7 @@ dependencyResolutionManagement {
}
filter { includeGroup("com.yarnpkg") }
}
//endregion
}
}

Expand Down
Loading