Skip to content

Commit af77f42

Browse files
authored
De-duplicated the version override in the actual project and in buildSrc (#460)
1 parent 666866c commit af77f42

File tree

4 files changed

+87
-115
lines changed

4 files changed

+87
-115
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import org.gradle.kotlin.dsl.maven
2+
3+
pluginManagement {
4+
repositories {
5+
mavenCentral()
6+
gradlePluginPortal()
7+
8+
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
9+
if (additionalRepositoryProperty.isPresent) {
10+
maven(additionalRepositoryProperty.get()) {
11+
name = "KotlinDevRepo"
12+
}
13+
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
14+
}
15+
16+
maven("https://oss.sonatype.org/content/repositories/snapshots") {
17+
mavenContent { snapshotsOnly() }
18+
}
19+
}
20+
}
21+
22+
dependencyResolutionManagement {
23+
24+
@Suppress("UnstableApiUsage")
25+
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
26+
27+
@Suppress("UnstableApiUsage")
28+
repositories {
29+
maven("https://oss.sonatype.org/content/repositories/snapshots") {
30+
mavenContent { snapshotsOnly() }
31+
}
32+
33+
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
34+
if (additionalRepositoryProperty.isPresent) {
35+
maven(additionalRepositoryProperty.get()) {
36+
name = "KotlinDevRepo"
37+
}
38+
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
39+
}
40+
41+
mavenCentral()
42+
43+
44+
// we have such a task https://youtrack.jetbrains.com/issue/KT-34732 to move these artifacts to the Maven repository,
45+
// but before that we need to have ivy for yarn and node dependencies
46+
exclusiveContent {
47+
forRepository {
48+
ivy("https://nodejs.org/dist") {
49+
name = "NodeJS repository"
50+
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
51+
metadataSources { artifact() }
52+
content { includeModule("org.nodejs", "node") }
53+
}
54+
}
55+
filter { includeGroup("org.nodejs") }
56+
}
57+
58+
exclusiveContent {
59+
forRepository {
60+
ivy("https://github.com/yarnpkg/yarn/releases/download") {
61+
name = "Yarn release repository"
62+
patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
63+
metadataSources { artifact() }
64+
content { includeModule("com.yarnpkg", "yarn") }
65+
}
66+
}
67+
filter { includeGroup("com.yarnpkg") }
68+
}
69+
}
70+
71+
versionCatalogs {
72+
register("libs").configure {
73+
val kotlinVersion = providers.gradleProperty("kotlin_version").orNull
74+
if (kotlinVersion != null) {
75+
version("kotlin", kotlinVersion)
76+
}
77+
}
78+
}
79+
}

buildSrc/settings.gradle.kts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,19 @@ pluginManagement {
44
includeBuild("../build-settings-logic")
55
}
66

7+
// For buildSrc we need to declare a custom path to toml file with versions' catalog.
8+
// But for a root project we can't set `from` inside `versionCatalogs` catalog block for the default `libs` catalog.
9+
// (see https://github.com/gradle/gradle/issues/21328)
10+
// That is why it is not fully moved to the dependencyResolutionManagement block in the settings convention plugin.
711
dependencyResolutionManagement {
8-
9-
@Suppress("UnstableApiUsage")
10-
repositories {
11-
/*
12-
* This property group is used to build kotlinx.atomicfu against Kotlin compiler snapshots.
13-
* When build_snapshot_train is set to true, mavenLocal and Sonatype snapshots are added to repository list
14-
* (the former is required for AFU and public, the latter is required for compiler snapshots).
15-
* DO NOT change the name of these properties without adapting kotlinx.train build chain.
16-
*/
17-
val buildSnapshotTrainGradleProperty = providers.gradleProperty("build_snapshot_train")
18-
if (buildSnapshotTrainGradleProperty.isPresent) {
19-
maven(url = uri("https://oss.sonatype.org/content/repositories/snapshots"))
20-
}
21-
22-
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
23-
if (additionalRepositoryProperty.isPresent) {
24-
maven(url = uri(additionalRepositoryProperty.get()))
25-
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
26-
}
27-
28-
mavenCentral()
29-
}
30-
3112
versionCatalogs {
32-
create("libs") {
13+
getByName("libs") {
3314
from(files("../gradle/libs.versions.toml"))
34-
35-
val kotlinVersion = providers.gradleProperty("kotlin_version").orNull
36-
if (kotlinVersion != null) {
37-
version("kotlin", kotlinVersion)
38-
}
3915
}
4016
}
4117
}
4218

4319
plugins {
20+
id("atomicfu-dependency-resolution-management")
4421
id("atomicfu-cache-redirector")
4522
}

integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/runner/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal fun Path.enableCacheRedirector() {
4040
.normalize()
4141
.toFile()
4242

43-
val gradleDir = resolve("gradle").also { it.createDirectories() }
43+
val gradleDir = resolve("gradle").createDirectories()
4444
redirectorScript.copyTo(gradleDir.resolve("cache-redirector.settings.gradle.kts").toFile())
4545

4646
val settingsGradle = resolve("settings.gradle")

settings.gradle.kts

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,10 @@ rootProject.name = "kotlinx-atomicfu"
22

33
pluginManagement {
44
includeBuild("build-settings-logic")
5-
repositories {
6-
mavenCentral()
7-
gradlePluginPortal()
8-
9-
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
10-
if (additionalRepositoryProperty.isPresent) {
11-
maven(url = uri(additionalRepositoryProperty.get()))
12-
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
13-
}
14-
15-
/*
16-
* This property group is used to build kotlinx.atomicfu against Kotlin compiler snapshots.
17-
* When build_snapshot_train is set to true, mavenLocal and Sonatype snapshots are added to repository list
18-
* (the former is required for AFU and public, the latter is required for compiler snapshots).
19-
* DO NOT change the name of these properties without adapting kotlinx.train build chain.
20-
*/
21-
val buildSnapshotTrainGradleProperty = providers.gradleProperty("build_snapshot_train")
22-
if (buildSnapshotTrainGradleProperty.isPresent) {
23-
maven(url = uri("https://oss.sonatype.org/content/repositories/snapshots"))
24-
}
25-
}
26-
}
27-
28-
dependencyResolutionManagement {
29-
30-
@Suppress("UnstableApiUsage")
31-
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
32-
33-
@Suppress("UnstableApiUsage")
34-
repositories {
35-
36-
/*
37-
* This property group is used to build kotlinx.atomicfu against Kotlin compiler snapshots.
38-
* When build_snapshot_train is set to true, mavenLocal and Sonatype snapshots are added to repository list
39-
* (the former is required for AFU and public, the latter is required for compiler snapshots).
40-
* DO NOT change the name of these properties without adapting kotlinx.train build chain.
41-
*/
42-
val buildSnapshotTrainGradleProperty = providers.gradleProperty("build_snapshot_train")
43-
if (buildSnapshotTrainGradleProperty.isPresent) {
44-
maven(url = uri("https://oss.sonatype.org/content/repositories/snapshots"))
45-
}
46-
47-
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
48-
if (additionalRepositoryProperty.isPresent) {
49-
maven(url = uri(additionalRepositoryProperty.get()))
50-
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
51-
}
52-
53-
mavenCentral()
54-
55-
// we have such a task https://youtrack.jetbrains.com/issue/KT-34732 to move these artifacts to the Maven repository,
56-
// but before that we need to have ivy for yarn and node dependencies
57-
exclusiveContent {
58-
forRepository {
59-
ivy("https://nodejs.org/dist") {
60-
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
61-
metadataSources { artifact() }
62-
content { includeModule("org.nodejs", "node") }
63-
}
64-
}
65-
filter { includeGroup("org.nodejs") }
66-
}
67-
68-
exclusiveContent {
69-
forRepository {
70-
ivy("https://github.com/yarnpkg/yarn/releases/download") {
71-
patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
72-
metadataSources { artifact() }
73-
content { includeModule("com.yarnpkg", "yarn") }
74-
}
75-
}
76-
filter { includeGroup("com.yarnpkg") }
77-
}
78-
79-
}
80-
81-
versionCatalogs {
82-
create("libs") {
83-
84-
val kotlinVersion = providers.gradleProperty("kotlin_version").orNull
85-
if (kotlinVersion != null) {
86-
version("kotlin", kotlinVersion)
87-
}
88-
}
89-
}
905
}
916

927
plugins {
8+
id("atomicfu-dependency-resolution-management")
939
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0")
9410
id("atomicfu-gradle-build-scan")
9511
id("atomicfu-gradle-build-cache")

0 commit comments

Comments
 (0)