Skip to content

Commit 8c371f3

Browse files
committed
Added proxy repository settings
1 parent 4e23f71 commit 8c371f3

File tree

9 files changed

+161
-44
lines changed

9 files changed

+161
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ detekt/reports/**
3535
# Ignore kover reports
3636
/kover
3737

38+
local.properties
3839
scan-journal.log

compiler-plugin/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pluginManagement {
1212
}
1313

1414
plugins {
15-
id("settings-conventions")
15+
id("conventions-repositories")
16+
id("conventions-version-resolution")
1617
id("conventions-develocity")
1718
}
1819

gradle-conventions-settings/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
rootProject.name = "gradle-conventions-settings"
66

77
// Code below is a hack because a chicken-egg problem, I can't use myself as a settings-plugin
8-
apply(from = "src/main/kotlin/settings-conventions.settings.gradle.kts")
8+
apply(from = "src/main/kotlin/conventions-repositories.settings.gradle.kts")
9+
apply(from = "src/main/kotlin/conventions-version-resolution.settings.gradle.kts")
910

1011
val kotlinVersion: KotlinVersion by extra
1112

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("DuplicatedCode", "MISSING_DEPENDENCY_CLASS")
6+
7+
import java.util.*
8+
9+
pluginManagement {
10+
fun logAbsentProperty(name: String): Nothing? {
11+
logger.info("Property '$name' is not present for repository credentials.")
12+
13+
return null
14+
}
15+
16+
@Suppress("RemoveRedundantQualifierName")
17+
fun getLocalProperties(): java.util.Properties {
18+
return java.util.Properties().apply {
19+
val propertiesDir = File(
20+
rootDir.path
21+
.removeSuffix("/gradle-conventions")
22+
.removeSuffix("/gradle-conventions-settings")
23+
.removeSuffix("/ksp-plugin")
24+
.removeSuffix("/compiler-plugin")
25+
.removeSuffix("/gradle-plugin")
26+
)
27+
val localFile = File(propertiesDir, "local.properties")
28+
if (localFile.exists()) {
29+
localFile.inputStream().use { load(it) }
30+
}
31+
}
32+
}
33+
34+
fun getSpaceUsername(): String? {
35+
val username = "kotlinx.rpc.team.space.username"
36+
return getLocalProperties()[username] as String?
37+
?: settings.providers.gradleProperty(username).orNull
38+
?: System.getenv(username)?.ifEmpty { null }
39+
?: logAbsentProperty(username)
40+
}
41+
42+
fun getSpacePassword(): String? {
43+
val password = "kotlinx.rpc.team.space.password"
44+
return getLocalProperties()[password] as String?
45+
?: settings.providers.gradleProperty(password).orNull
46+
?: System.getenv(password)?.ifEmpty { null }
47+
?: logAbsentProperty(password)
48+
}
49+
50+
/**
51+
* Creates a publishing repository targeting Space Packages on jetbrains.team.
52+
*
53+
* @param repoName the name of the Space Packages repository
54+
*/
55+
fun RepositoryHandler.jbTeamPackages(repoName: String) {
56+
maven {
57+
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
58+
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
59+
credentials {
60+
username = getSpaceUsername()
61+
password = getSpacePassword()
62+
}
63+
}
64+
}
65+
66+
fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
67+
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
68+
69+
repositories {
70+
buildDeps()
71+
buildDepsEap()
72+
}
73+
}
74+
75+
gradle.rootProject {
76+
fun logAbsentProperty(name: String): Nothing? {
77+
logger.info("Property '$name' is not present for repository credentials.")
78+
79+
return null
80+
}
81+
82+
fun getLocalProperties(): Properties {
83+
return Properties().apply {
84+
val propertiesDir = File(
85+
rootDir.path
86+
.removeSuffix("/gradle-conventions")
87+
.removeSuffix("/gradle-conventions-settings")
88+
.removeSuffix("/ksp-plugin")
89+
.removeSuffix("/compiler-plugin")
90+
.removeSuffix("/gradle-plugin")
91+
)
92+
val localFile = File(propertiesDir, "local.properties")
93+
if (localFile.exists()) {
94+
localFile.inputStream().use { load(it) }
95+
}
96+
}
97+
}
98+
99+
fun getSpaceUsername(): String? {
100+
val username = "kotlinx.rpc.team.space.username"
101+
return getLocalProperties()[username] as String?
102+
?: settings.providers.gradleProperty(username).orNull
103+
?: System.getenv(username)?.ifEmpty { null }
104+
?: logAbsentProperty(username)
105+
}
106+
107+
fun getSpacePassword(): String? {
108+
val password = "kotlinx.rpc.team.space.password"
109+
return getLocalProperties()[password] as String?
110+
?: settings.providers.gradleProperty(password).orNull
111+
?: System.getenv(password)?.ifEmpty { null }
112+
?: logAbsentProperty(password)
113+
}
114+
115+
/**
116+
* Creates a publishing repository targeting Space Packages on jetbrains.team.
117+
*
118+
* @param repoName the name of the Space Packages repository
119+
*/
120+
fun RepositoryHandler.jbTeamPackages(repoName: String) {
121+
maven {
122+
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
123+
124+
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
125+
credentials {
126+
username = getSpaceUsername()
127+
password = getSpacePassword()
128+
}
129+
}
130+
}
131+
132+
fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
133+
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
134+
135+
allprojects {
136+
buildscript {
137+
repositories {
138+
buildDeps()
139+
buildDepsEap()
140+
}
141+
}
142+
repositories {
143+
buildDeps()
144+
buildDepsEap()
145+
}
146+
}
147+
}

gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts renamed to gradle-conventions-settings/src/main/kotlin/conventions-version-resolution.settings.gradle.kts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ import java.nio.file.Files
99
import java.nio.file.OpenOption
1010
import java.nio.file.Path
1111

12-
pluginManagement {
13-
repositories {
14-
mavenCentral()
15-
gradlePluginPortal()
16-
}
17-
}
18-
1912
fun Path.bufferedReader(
2013
charset: Charset = Charsets.UTF_8,
2114
bufferSize: Int = DEFAULT_BUFFER_SIZE,
@@ -226,20 +219,3 @@ dependencyResolutionManagement {
226219
}
227220
}
228221
}
229-
230-
// ### OTHER SETTINGS SECTION ###
231-
232-
gradle.rootProject {
233-
allprojects {
234-
buildscript {
235-
repositories {
236-
gradlePluginPortal()
237-
mavenCentral()
238-
}
239-
}
240-
241-
repositories {
242-
mavenCentral()
243-
}
244-
}
245-
}

gradle-conventions/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pluginManagement {
2020
includeBuild("../gradle-conventions-settings")
2121

2222
plugins {
23-
id("settings-conventions")
23+
id("conventions-repositories")
24+
id("conventions-version-resolution")
2425
}
2526

2627
whenKotlinLatest {

gradle-plugin/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pluginManagement {
1212
}
1313

1414
plugins {
15-
id("settings-conventions")
15+
id("conventions-repositories")
16+
id("conventions-version-resolution")
1617
}
1718

1819
includeRootAsPublic()

settings.gradle.kts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3-
*/
1+
import util.otherwise
2+
import util.whenKotlinIsAtLeast
43

54
rootProject.name = "kotlinx-rpc"
65

@@ -12,11 +11,6 @@ pluginManagement {
1211

1312
includeBuild("gradle-plugin")
1413

15-
repositories {
16-
mavenCentral()
17-
gradlePluginPortal()
18-
}
19-
2014
resolutionStrategy {
2115
eachPlugin {
2216
if (requested.id.id == "kotlinx-atomicfu") {
@@ -27,9 +21,10 @@ pluginManagement {
2721
}
2822

2923
plugins {
30-
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
31-
id("settings-conventions")
24+
id("conventions-repositories")
25+
id("conventions-version-resolution")
3226
id("conventions-develocity")
27+
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
3328
}
3429

3530
dependencyResolutionManagement {

tests/compiler-plugin-tests/build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ plugins {
1212

1313
// this setup – courtesy of https://github.com/demiurg906/kotlin-compiler-plugin-template/tree/master
1414

15-
repositories {
16-
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
17-
maven("https://www.jetbrains.com/intellij-repository/releases")
18-
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
19-
}
20-
2115
sourceSets {
2216
test {
2317
java.srcDir("src/test-gen")

0 commit comments

Comments
 (0)