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+ fun logAbsentProperty (name : String , env : String ): Nothing? {
9+ logger.info(" Property '$name ' (or env var ' $env ') is not present for repository credentials." )
1210
1311 return null
1412 }
@@ -33,18 +31,20 @@ pluginManagement {
3331
3432 fun getSpaceUsername (): String? {
3533 val username = " kotlinx.rpc.team.space.username"
34+ val usernameEnv = " kotlinx_rpc_team_space_username"
3635 return getLocalProperties()[username] as String?
3736 ? : settings.providers.gradleProperty(username).orNull
38- ? : System .getenv(username )?.ifEmpty { null }
39- ? : logAbsentProperty(username)
37+ ? : System .getenv(usernameEnv )?.ifEmpty { null }
38+ ? : logAbsentProperty(username, usernameEnv )
4039 }
4140
4241 fun getSpacePassword (): String? {
4342 val password = " kotlinx.rpc.team.space.password"
43+ val passwordEnv = " kotlinx_rpc_team_space_password"
4444 return getLocalProperties()[password] as String?
4545 ? : settings.providers.gradleProperty(password).orNull
46- ? : System .getenv(password )?.ifEmpty { null }
47- ? : logAbsentProperty(password)
46+ ? : System .getenv(passwordEnv )?.ifEmpty { null }
47+ ? : logAbsentProperty(password, passwordEnv )
4848 }
4949
5050 /* *
@@ -56,9 +56,15 @@ pluginManagement {
5656 maven {
5757 name = repoName.split(" -" ).joinToString(" " ) { it.replaceFirstChar { c -> c.titlecase() } }
5858 url = uri(" https://packages.jetbrains.team/maven/p/krpc/$repoName " )
59- credentials {
60- username = getSpaceUsername()
61- password = getSpacePassword()
59+
60+ val username = getSpaceUsername()
61+ val password = getSpacePassword()
62+
63+ if (username != null && password != null ) {
64+ credentials {
65+ this .username = username
66+ this .password = password
67+ }
6268 }
6369 }
6470 }
@@ -73,14 +79,14 @@ pluginManagement {
7379}
7480
7581gradle.rootProject {
76- fun logAbsentProperty (name : String ): Nothing? {
77- logger.info(" Property '$name ' is not present for repository credentials." )
82+ fun logAbsentProperty (name : String , env : String ): Nothing? {
83+ logger.info(" Property '$name ' (or env var ' $env ') is not present for repository credentials." )
7884
7985 return null
8086 }
8187
82- fun getLocalProperties (): Properties {
83- return Properties ().apply {
88+ fun getLocalProperties (): java.util. Properties {
89+ return java.util. Properties ().apply {
8490 val propertiesDir = File (
8591 rootDir.path
8692 .removeSuffix(" /gradle-conventions" )
@@ -98,18 +104,20 @@ gradle.rootProject {
98104
99105 fun getSpaceUsername (): String? {
100106 val username = " kotlinx.rpc.team.space.username"
107+ val usernameEnv = " kotlinx_rpc_team_space_username"
101108 return getLocalProperties()[username] as String?
102109 ? : settings.providers.gradleProperty(username).orNull
103- ? : System .getenv(username )?.ifEmpty { null }
104- ? : logAbsentProperty(username)
110+ ? : System .getenv(usernameEnv )?.ifEmpty { null }
111+ ? : logAbsentProperty(username, usernameEnv )
105112 }
106113
107114 fun getSpacePassword (): String? {
108115 val password = " kotlinx.rpc.team.space.password"
116+ val passwordEnv = " kotlinx_rpc_team_space_password"
109117 return getLocalProperties()[password] as String?
110118 ? : settings.providers.gradleProperty(password).orNull
111- ? : System .getenv(password )?.ifEmpty { null }
112- ? : logAbsentProperty(password)
119+ ? : System .getenv(passwordEnv )?.ifEmpty { null }
120+ ? : logAbsentProperty(password, passwordEnv )
113121 }
114122
115123 /* *
@@ -122,9 +130,15 @@ gradle.rootProject {
122130 name = repoName.split(" -" ).joinToString(" " ) { it.replaceFirstChar { c -> c.titlecase() } }
123131
124132 url = uri(" https://packages.jetbrains.team/maven/p/krpc/$repoName " )
125- credentials {
126- username = getSpaceUsername()
127- password = getSpacePassword()
133+
134+ val username = getSpaceUsername()
135+ val password = getSpacePassword()
136+
137+ if (username != null && password != null ) {
138+ credentials {
139+ this .username = username
140+ this .password = password
141+ }
128142 }
129143 }
130144 }
0 commit comments