-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.gradle.kts
More file actions
118 lines (106 loc) · 4.07 KB
/
settings.gradle.kts
File metadata and controls
118 lines (106 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.net.URI
/*
* SonarSource Cloud Native Gradle Modules
* Copyright (C) 2024-2026 SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource Sàrl.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
pluginManagement {
// Note: because of the way how settings are initialized, we cannot reuse functions defined later in this file.
val artifactoryUsername = providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME")
.orElse(providers.environmentVariable("ARTIFACTORY_USERNAME"))
.orElse(providers.gradleProperty("artifactoryUsername"))
val artifactoryPassword = providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD")
.orElse(providers.environmentVariable("ARTIFACTORY_ACCESS_TOKEN"))
.orElse(providers.gradleProperty("artifactoryPassword"))
repositories {
if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) {
maven {
name = "artifactory"
url = uri("https://repox.jfrog.io/repox/plugins.gradle.org")
authentication {
credentials {
username = artifactoryUsername.get()
password = artifactoryPassword.get()
}
}
}
} else {
mavenCentral()
gradlePluginPortal()
}
}
}
plugins {
id("com.gradle.develocity") version "4.0.3"
}
rootProject.name = "cloud-native-gradle-modules"
include("gradle-modules")
dependencyResolutionManagement {
repositories {
ifAuthenticatedOrElse(providers, { artifactoryUsername, artifactoryPassword ->
repox("sonarsource", artifactoryUsername, artifactoryPassword, ::uri)
repox("plugins.gradle.org", artifactoryUsername, artifactoryPassword, ::uri)
}) {
mavenCentral()
gradlePluginPortal()
}
}
}
develocity {
server.set("https://develocity-public.sonar.build/")
}
val isCI = System.getenv("CI") != null
buildCache {
local {
isEnabled = !isCI
}
remote(develocity.buildCache) {
isEnabled = true
isPush = isCI
}
}
internal fun RepositoryHandler.repox(
repository: String,
artifactoryUsername: String,
artifactoryPassword: String,
uri: (Any) -> URI,
): MavenArtifactRepository =
maven {
name = "artifactory"
url = uri("https://repox.jfrog.io/repox/$repository")
authentication {
credentials {
username = artifactoryUsername
password = artifactoryPassword
}
}
}
internal fun ifAuthenticatedOrElse(
providers: ProviderFactory,
onAuthenticated: (artifactoryUsername: String, artifactoryPassword: String) -> Unit,
onNotAuthenticated: () -> Unit,
) {
// This authentication relies on env vars configured on Cirrus CI or on Gradle properties (`-P<prop>` flags or `gradle.properties` file)
val artifactoryUsername = providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME")
.orElse(providers.environmentVariable("ARTIFACTORY_USERNAME"))
.orElse(providers.gradleProperty("artifactoryUsername"))
val artifactoryPassword = providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD")
.orElse(providers.environmentVariable("ARTIFACTORY_ACCESS_TOKEN"))
.orElse(providers.gradleProperty("artifactoryPassword"))
if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) {
onAuthenticated(artifactoryUsername.get(), artifactoryPassword.get())
} else {
onNotAuthenticated()
}
}