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

Added proxy repository settings #191

Merged
merged 6 commits into from
Nov 4, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ detekt/reports/**
# Ignore kover reports
/kover

local.properties
scan-journal.log
39 changes: 7 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,22 @@
*/

import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import util.configureApiValidation
import util.configureNpm
import util.configureProjectReport
import util.libs

plugins {
alias(libs.plugins.serialization) apply false
alias(libs.plugins.kotlinx.rpc) apply false
alias(libs.plugins.conventions.kover)
alias(libs.plugins.conventions.gradle.doctor)
alias(libs.plugins.binary.compatibility.validator)
alias(libs.plugins.atomicfu)
}

// useful for dependencies introspection
// run ./gradlew htmlDependencyReport
// Report can normally be found in build/reports/project/dependencies/index.html
allprojects {
plugins.apply("project-report")
}

object Const {
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.utils.InternalRPCApi"
}

apiValidation {
ignoredPackages.add("kotlinx.rpc.internal")
ignoredPackages.add("kotlinx.rpc.krpc.internal")

ignoredProjects.addAll(
listOf(
"compiler-plugin-tests",
"krpc-test",
"utils",
)
)

nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
}
configureProjectReport()
configureNpm()
configureApiValidation()

val kotlinVersionFull: String by extra

Expand All @@ -52,13 +32,8 @@ println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersionFu
// If the prefix of the kPRC version is not Kotlin gradle plugin version – you have a problem :)
// Probably some dependency brings kotlin with the later version.
// To mitigate so, refer to `versions-root/kotlin-version-lookup.json`
// and its usage in `gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts`
// and its usage in `gradle-conventions-settings/src/main/kotlin/conventions-version-resolution.settings.gradle.kts`
val kotlinGPVersion = getKotlinPluginVersion()
if (kotlinVersionFull != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersionFull, KGP version: $kotlinGPVersion")
}

// necessary for CI js tests
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
}
3 changes: 2 additions & 1 deletion compiler-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pluginManagement {
}

plugins {
id("settings-conventions")
id("conventions-repositories")
id("conventions-version-resolution")
id("conventions-develocity")
}

Expand Down
1 change: 1 addition & 0 deletions gradle-conventions-settings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val isLatestKotlinVersion: Boolean by extra
dependencies {
api(libs.kotlin.gradle.plugin)
api(libs.detekt.gradle.plugin)
api(libs.binary.compatibility.validator.gradle.plugin)

if (isLatestKotlinVersion) {
api(libs.kover.gradle.plugin)
Expand Down
5 changes: 0 additions & 5 deletions gradle-conventions-settings/develocity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ configurations.configureEach {
}
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("com.gradle:develocity-gradle-plugin:3.17")
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.0.2")
Expand Down
3 changes: 2 additions & 1 deletion gradle-conventions-settings/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
rootProject.name = "gradle-conventions-settings"

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

val kotlinVersion: KotlinVersion by extra

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("DuplicatedCode")

pluginManagement {
fun logAbsentProperty(name: String): Nothing? {
logger.info("Property '$name' is not present for repository credentials.")

return null
}

fun getEnv(propertyName: String): String? = System.getenv(
propertyName.replace(".", "_").uppercase()
)?.ifEmpty { null }

fun getLocalProperties(): java.util.Properties {
return java.util.Properties().apply {
val propertiesDir = File(
rootDir.path
.removeSuffix("/gradle-conventions")
.removeSuffix("/gradle-conventions-settings")
.removeSuffix("/compiler-plugin")
.removeSuffix("/gradle-plugin")
)
val localFile = File(propertiesDir, "local.properties")
if (localFile.exists()) {
localFile.inputStream().use { load(it) }
}
}
}

fun getSpacePassword(): String? {
val password = "kotlinx.rpc.team.space.password"
return getLocalProperties()[password] as String?
?: settings.providers.gradleProperty(password).orNull
?: getEnv(password)
?: logAbsentProperty(password)
}

/**
* Creates a publishing repository targeting Space Packages on jetbrains.team.
*
* @param repoName the name of the Space Packages repository
*/
fun RepositoryHandler.jbTeamPackages(repoName: String) {
maven {
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")

val spacePassword = getSpacePassword()

if (spacePassword != null) {
credentials(HttpHeaderCredentials::class.java) {
name = "Authorization"
value = "Bearer $spacePassword"
}

authentication {
create<HttpHeaderAuthentication>("http_auth_header")
}
} else {
logger.info("Skipping adding credentials for Space repository '$repoName'")
}
}
}

fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")

repositories {
val useProxyProperty = getLocalProperties()["kotlinx.rpc.useProxyRepositories"] as String?
val useProxy = useProxyProperty == null || useProxyProperty == "true"

if (useProxy) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
gradlePluginPortal()
}
}
}

gradle.rootProject {
fun logAbsentProperty(name: String): Nothing? {
logger.info("Property '$name' is not present for repository credentials.")

return null
}

fun getEnv(propertyName: String): String? = System.getenv(
propertyName.replace(".", "_").uppercase()
)?.ifEmpty { null }

fun getLocalProperties(): java.util.Properties {
return java.util.Properties().apply {
val propertiesDir = File(
rootDir.path
.removeSuffix("/gradle-conventions")
.removeSuffix("/gradle-conventions-settings")
.removeSuffix("/compiler-plugin")
.removeSuffix("/gradle-plugin")
)
val localFile = File(propertiesDir, "local.properties")
if (localFile.exists()) {
localFile.inputStream().use { load(it) }
}
}
}

fun java.util.Properties.isUsingProxyRepositories(): Boolean {
val useProxyProperty = this["kotlinx.rpc.useProxyRepositories"] as String?
return useProxyProperty == null || useProxyProperty == "true"
}

fun getSpacePassword(): String? {
val password = "kotlinx.rpc.team.space.password"
return getLocalProperties()[password] as String?
?: settings.providers.gradleProperty(password).orNull
?: getEnv(password)
?: logAbsentProperty(password)
}

/**
* Creates a publishing repository targeting Space Packages on jetbrains.team.
*
* @param repoName the name of the Space Packages repository
*/
fun RepositoryHandler.jbTeamPackages(repoName: String) {
maven {
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")

val spacePassword = getSpacePassword()

if (spacePassword != null) {
credentials(HttpHeaderCredentials::class.java) {
name = "Authorization"
value = "Bearer $spacePassword"
}

authentication {
create<HttpHeaderAuthentication>("http_auth_header")
}
} else {
logger.info("Skipping adding credentials for Space repository '$repoName'")
}
}
}

fun RepositoryHandler.buildDeps() = jbTeamPackages(repoName = "build-deps")
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")

allprojects {
val localProps = getLocalProperties()

this.extra["spacePassword"] = getSpacePassword()
this.extra["localProperties"] = localProps
this.extra["useProxyRepositories"] = localProps.isUsingProxyRepositories()

val useProxy = localProps.isUsingProxyRepositories()

buildscript {
repositories {
if (useProxy) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
gradlePluginPortal()
}
}
}
repositories {
if (useProxy) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
gradlePluginPortal()

maven("https://www.jetbrains.com/intellij-repository/releases")

maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")

maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import java.nio.file.Files
import java.nio.file.OpenOption
import java.nio.file.Path

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

fun Path.bufferedReader(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE,
Expand Down Expand Up @@ -226,20 +219,3 @@ dependencyResolutionManagement {
}
}
}

// ### OTHER SETTINGS SECTION ###

gradle.rootProject {
allprojects {
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

repositories {
mavenCentral()
}
}
}
28 changes: 28 additions & 0 deletions gradle-conventions-settings/src/main/kotlin/util/apiValidation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import kotlinx.validation.ApiValidationExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.the

fun Project.configureApiValidation() {
plugins.apply(libs.plugins.binary.compatibility.validator.get().pluginId)

the<ApiValidationExtension>().apply {
ignoredPackages.add("kotlinx.rpc.internal")
ignoredPackages.add("kotlinx.rpc.krpc.internal")

ignoredProjects.addAll(
listOf(
"compiler-plugin-tests",
"krpc-test",
"utils",
)
)

nonPublicMarkers.add("kotlinx.rpc.internal.utils.InternalRPCApi")
}
}
Loading