44
55@file:Suppress(" DuplicatedCode" , " MISSING_DEPENDENCY_CLASS" )
66
7- import java.util.*
8-
97pluginManagement {
10- fun logAbsentProperty (name : String ): Nothing? {
11- logger.info(" Property '$name ' is not present for repository credentials." )
8+ val isCI = System .getenv(" TEAMCITY_VERSION" ) != null
129
13- return null
10+ fun requiredPropertyError (name : String , env : String ): Nothing {
11+ throw GradleException (" Property '$name ' (or env var '$env ') is not present for repository credentials." )
1412 }
1513
16- @Suppress(" RemoveRedundantQualifierName" )
1714 fun getLocalProperties (): java.util.Properties {
1815 return java.util.Properties ().apply {
1916 val propertiesDir = File (
@@ -31,20 +28,22 @@ pluginManagement {
3128 }
3229 }
3330
34- fun getSpaceUsername (): String? {
31+ fun getSpaceUsername (): String {
3532 val username = " kotlinx.rpc.team.space.username"
33+ val usernameEnv = " kotlinx_rpc_team_space_username"
3634 return getLocalProperties()[username] as String?
3735 ? : settings.providers.gradleProperty(username).orNull
38- ? : System .getenv(username )?.ifEmpty { null }
39- ? : logAbsentProperty (username)
36+ ? : System .getenv(usernameEnv )?.ifEmpty { null }
37+ ? : requiredPropertyError (username, usernameEnv )
4038 }
4139
42- fun getSpacePassword (): String? {
40+ fun getSpacePassword (): String {
4341 val password = " kotlinx.rpc.team.space.password"
42+ val passwordEnv = " kotlinx_rpc_team_space_password"
4443 return getLocalProperties()[password] as String?
4544 ? : settings.providers.gradleProperty(password).orNull
46- ? : System .getenv(password )?.ifEmpty { null }
47- ? : logAbsentProperty (password)
45+ ? : System .getenv(passwordEnv )?.ifEmpty { null }
46+ ? : requiredPropertyError (password, passwordEnv )
4847 }
4948
5049 /* *
@@ -56,6 +55,7 @@ pluginManagement {
5655 maven {
5756 name = repoName.split(" -" ).joinToString(" " ) { it.replaceFirstChar { c -> c.titlecase() } }
5857 url = uri(" https://packages.jetbrains.team/maven/p/krpc/$repoName " )
58+
5959 credentials {
6060 username = getSpaceUsername()
6161 password = getSpacePassword()
@@ -67,20 +67,25 @@ pluginManagement {
6767 fun RepositoryHandler.buildDepsEap () = jbTeamPackages(repoName = " build-deps-eap" )
6868
6969 repositories {
70- buildDeps()
71- buildDepsEap()
70+ if (isCI) {
71+ buildDeps()
72+ buildDepsEap()
73+ } else {
74+ mavenCentral()
75+ gradlePluginPortal()
76+ }
7277 }
7378}
7479
7580gradle.rootProject {
76- fun logAbsentProperty (name : String ): Nothing? {
77- logger.info(" Property '$name ' is not present for repository credentials." )
81+ val isCI = System .getenv(" TEAMCITY_VERSION" ) != null
7882
79- return null
83+ fun requiredPropertyError (name : String , env : String ): Nothing {
84+ throw GradleException (" Property '$name ' (or env var '$env ') is not present for repository credentials." )
8085 }
8186
82- fun getLocalProperties (): Properties {
83- return Properties ().apply {
87+ fun getLocalProperties (): java.util. Properties {
88+ return java.util. Properties ().apply {
8489 val propertiesDir = File (
8590 rootDir.path
8691 .removeSuffix(" /gradle-conventions" )
@@ -96,20 +101,22 @@ gradle.rootProject {
96101 }
97102 }
98103
99- fun getSpaceUsername (): String? {
104+ fun getSpaceUsername (): String {
100105 val username = " kotlinx.rpc.team.space.username"
106+ val usernameEnv = " kotlinx_rpc_team_space_username"
101107 return getLocalProperties()[username] as String?
102108 ? : settings.providers.gradleProperty(username).orNull
103- ? : System .getenv(username )?.ifEmpty { null }
104- ? : logAbsentProperty (username)
109+ ? : System .getenv(usernameEnv )?.ifEmpty { null }
110+ ? : requiredPropertyError (username, usernameEnv )
105111 }
106112
107- fun getSpacePassword (): String? {
113+ fun getSpacePassword (): String {
108114 val password = " kotlinx.rpc.team.space.password"
115+ val passwordEnv = " kotlinx_rpc_team_space_password"
109116 return getLocalProperties()[password] as String?
110117 ? : settings.providers.gradleProperty(password).orNull
111- ? : System .getenv(password )?.ifEmpty { null }
112- ? : logAbsentProperty (password)
118+ ? : System .getenv(passwordEnv )?.ifEmpty { null }
119+ ? : requiredPropertyError (password, passwordEnv )
113120 }
114121
115122 /* *
@@ -122,6 +129,7 @@ gradle.rootProject {
122129 name = repoName.split(" -" ).joinToString(" " ) { it.replaceFirstChar { c -> c.titlecase() } }
123130
124131 url = uri(" https://packages.jetbrains.team/maven/p/krpc/$repoName " )
132+
125133 credentials {
126134 username = getSpaceUsername()
127135 password = getSpacePassword()
@@ -135,13 +143,28 @@ gradle.rootProject {
135143 allprojects {
136144 buildscript {
137145 repositories {
138- buildDeps()
139- buildDepsEap()
146+ if (isCI) {
147+ buildDeps()
148+ buildDepsEap()
149+ } else {
150+ mavenCentral()
151+ gradlePluginPortal()
152+ }
140153 }
141154 }
155+
142156 repositories {
143- buildDeps()
144- buildDepsEap()
157+ if (isCI) {
158+ buildDeps()
159+ buildDepsEap()
160+ } else {
161+ mavenCentral()
162+ gradlePluginPortal()
163+ maven(" https://www.jetbrains.com/intellij-repository/releases" )
164+ maven(" https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" )
165+ maven(" https://maven.pkg.jetbrains.space/public/p/ktor/eap" )
166+ maven(" https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap" )
167+ }
145168 }
146169 }
147170}
0 commit comments