Skip to content

Commit 4b4bd96

Browse files
authored
Added proxy repository settings (#191)
1 parent 4e23f71 commit 4b4bd96

21 files changed

+885
-636
lines changed

.gitignore

+1
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

build.gradle.kts

+7-32
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,22 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import util.configureApiValidation
7+
import util.configureNpm
8+
import util.configureProjectReport
69
import util.libs
710

811
plugins {
912
alias(libs.plugins.serialization) apply false
1013
alias(libs.plugins.kotlinx.rpc) apply false
1114
alias(libs.plugins.conventions.kover)
1215
alias(libs.plugins.conventions.gradle.doctor)
13-
alias(libs.plugins.binary.compatibility.validator)
1416
alias(libs.plugins.atomicfu)
1517
}
1618

17-
// useful for dependencies introspection
18-
// run ./gradlew htmlDependencyReport
19-
// Report can normally be found in build/reports/project/dependencies/index.html
20-
allprojects {
21-
plugins.apply("project-report")
22-
}
23-
24-
object Const {
25-
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.utils.InternalRPCApi"
26-
}
27-
28-
apiValidation {
29-
ignoredPackages.add("kotlinx.rpc.internal")
30-
ignoredPackages.add("kotlinx.rpc.krpc.internal")
31-
32-
ignoredProjects.addAll(
33-
listOf(
34-
"compiler-plugin-tests",
35-
"krpc-test",
36-
"utils",
37-
)
38-
)
39-
40-
nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
41-
}
19+
configureProjectReport()
20+
configureNpm()
21+
configureApiValidation()
4222

4323
val kotlinVersionFull: String by extra
4424

@@ -52,13 +32,8 @@ println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersionFu
5232
// If the prefix of the kPRC version is not Kotlin gradle plugin version – you have a problem :)
5333
// Probably some dependency brings kotlin with the later version.
5434
// To mitigate so, refer to `versions-root/kotlin-version-lookup.json`
55-
// and its usage in `gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts`
35+
// and its usage in `gradle-conventions-settings/src/main/kotlin/conventions-version-resolution.settings.gradle.kts`
5636
val kotlinGPVersion = getKotlinPluginVersion()
5737
if (kotlinVersionFull != kotlinGPVersion) {
5838
error("KGP version mismatch. Project version: $kotlinVersionFull, KGP version: $kotlinGPVersion")
5939
}
60-
61-
// necessary for CI js tests
62-
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
63-
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
64-
}

compiler-plugin/settings.gradle.kts

+2-1
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/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ val isLatestKotlinVersion: Boolean by extra
2020
dependencies {
2121
api(libs.kotlin.gradle.plugin)
2222
api(libs.detekt.gradle.plugin)
23+
api(libs.binary.compatibility.validator.gradle.plugin)
2324

2425
if (isLatestKotlinVersion) {
2526
api(libs.kover.gradle.plugin)

gradle-conventions-settings/develocity/build.gradle.kts

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ configurations.configureEach {
1515
}
1616
}
1717

18-
repositories {
19-
mavenCentral()
20-
gradlePluginPortal()
21-
}
22-
2318
dependencies {
2419
implementation("com.gradle:develocity-gradle-plugin:3.17")
2520
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.0.2")

gradle-conventions-settings/settings.gradle.kts

+2-1
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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")
6+
7+
pluginManagement {
8+
fun logAbsentProperty(name: String): Nothing? {
9+
logger.info("Property '$name' is not present for repository credentials.")
10+
11+
return null
12+
}
13+
14+
fun getEnv(propertyName: String): String? = System.getenv(
15+
propertyName.replace(".", "_").uppercase()
16+
)?.ifEmpty { null }
17+
18+
fun getLocalProperties(): java.util.Properties {
19+
return java.util.Properties().apply {
20+
val propertiesDir = File(
21+
rootDir.path
22+
.removeSuffix("/gradle-conventions")
23+
.removeSuffix("/gradle-conventions-settings")
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 getSpacePassword(): String? {
35+
val password = "kotlinx.rpc.team.space.password"
36+
return getLocalProperties()[password] as String?
37+
?: settings.providers.gradleProperty(password).orNull
38+
?: getEnv(password)
39+
?: logAbsentProperty(password)
40+
}
41+
42+
/**
43+
* Creates a publishing repository targeting Space Packages on jetbrains.team.
44+
*
45+
* @param repoName the name of the Space Packages repository
46+
*/
47+
fun RepositoryHandler.jbTeamPackages(repoName: String) {
48+
maven {
49+
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
50+
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
51+
52+
val spacePassword = getSpacePassword()
53+
54+
if (spacePassword != null) {
55+
credentials(HttpHeaderCredentials::class.java) {
56+
name = "Authorization"
57+
value = "Bearer $spacePassword"
58+
}
59+
60+
authentication {
61+
create<HttpHeaderAuthentication>("http_auth_header")
62+
}
63+
} else {
64+
logger.info("Skipping adding credentials for Space repository '$repoName'")
65+
}
66+
}
67+
}
68+
69+
fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
70+
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
71+
72+
repositories {
73+
val useProxyProperty = getLocalProperties()["kotlinx.rpc.useProxyRepositories"] as String?
74+
val useProxy = useProxyProperty == null || useProxyProperty == "true"
75+
76+
if (useProxy) {
77+
buildDeps()
78+
buildDepsEap()
79+
} else {
80+
mavenCentral()
81+
gradlePluginPortal()
82+
}
83+
}
84+
}
85+
86+
gradle.rootProject {
87+
fun logAbsentProperty(name: String): Nothing? {
88+
logger.info("Property '$name' is not present for repository credentials.")
89+
90+
return null
91+
}
92+
93+
fun getEnv(propertyName: String): String? = System.getenv(
94+
propertyName.replace(".", "_").uppercase()
95+
)?.ifEmpty { null }
96+
97+
fun getLocalProperties(): java.util.Properties {
98+
return java.util.Properties().apply {
99+
val propertiesDir = File(
100+
rootDir.path
101+
.removeSuffix("/gradle-conventions")
102+
.removeSuffix("/gradle-conventions-settings")
103+
.removeSuffix("/compiler-plugin")
104+
.removeSuffix("/gradle-plugin")
105+
)
106+
val localFile = File(propertiesDir, "local.properties")
107+
if (localFile.exists()) {
108+
localFile.inputStream().use { load(it) }
109+
}
110+
}
111+
}
112+
113+
fun java.util.Properties.isUsingProxyRepositories(): Boolean {
114+
val useProxyProperty = this["kotlinx.rpc.useProxyRepositories"] as String?
115+
return useProxyProperty == null || useProxyProperty == "true"
116+
}
117+
118+
fun getSpacePassword(): String? {
119+
val password = "kotlinx.rpc.team.space.password"
120+
return getLocalProperties()[password] as String?
121+
?: settings.providers.gradleProperty(password).orNull
122+
?: getEnv(password)
123+
?: logAbsentProperty(password)
124+
}
125+
126+
/**
127+
* Creates a publishing repository targeting Space Packages on jetbrains.team.
128+
*
129+
* @param repoName the name of the Space Packages repository
130+
*/
131+
fun RepositoryHandler.jbTeamPackages(repoName: String) {
132+
maven {
133+
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
134+
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
135+
136+
val spacePassword = getSpacePassword()
137+
138+
if (spacePassword != null) {
139+
credentials(HttpHeaderCredentials::class.java) {
140+
name = "Authorization"
141+
value = "Bearer $spacePassword"
142+
}
143+
144+
authentication {
145+
create<HttpHeaderAuthentication>("http_auth_header")
146+
}
147+
} else {
148+
logger.info("Skipping adding credentials for Space repository '$repoName'")
149+
}
150+
}
151+
}
152+
153+
fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
154+
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
155+
156+
allprojects {
157+
val localProps = getLocalProperties()
158+
159+
this.extra["spacePassword"] = getSpacePassword()
160+
this.extra["localProperties"] = localProps
161+
this.extra["useProxyRepositories"] = localProps.isUsingProxyRepositories()
162+
163+
val useProxy = localProps.isUsingProxyRepositories()
164+
165+
buildscript {
166+
repositories {
167+
if (useProxy) {
168+
buildDeps()
169+
buildDepsEap()
170+
} else {
171+
mavenCentral()
172+
gradlePluginPortal()
173+
}
174+
}
175+
}
176+
repositories {
177+
if (useProxy) {
178+
buildDeps()
179+
buildDepsEap()
180+
} else {
181+
mavenCentral()
182+
gradlePluginPortal()
183+
184+
maven("https://www.jetbrains.com/intellij-repository/releases")
185+
186+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
187+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
188+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
189+
190+
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
191+
}
192+
}
193+
}
194+
}

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

-24
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-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
package util
6+
7+
import kotlinx.validation.ApiValidationExtension
8+
import org.gradle.api.Project
9+
import org.gradle.kotlin.dsl.the
10+
11+
fun Project.configureApiValidation() {
12+
plugins.apply(libs.plugins.binary.compatibility.validator.get().pluginId)
13+
14+
the<ApiValidationExtension>().apply {
15+
ignoredPackages.add("kotlinx.rpc.internal")
16+
ignoredPackages.add("kotlinx.rpc.krpc.internal")
17+
18+
ignoredProjects.addAll(
19+
listOf(
20+
"compiler-plugin-tests",
21+
"krpc-test",
22+
"utils",
23+
)
24+
)
25+
26+
nonPublicMarkers.add("kotlinx.rpc.internal.utils.InternalRPCApi")
27+
}
28+
}

0 commit comments

Comments
 (0)