@@ -14,9 +14,14 @@ import org.gradle.jvm.tasks.Jar
14
14
import org.gradle.jvm.toolchain.JavaLanguageVersion
15
15
import org.gradle.kotlin.dsl.*
16
16
import org.gradle.language.jvm.tasks.ProcessResources
17
+ import java.io.File
18
+ import java.net.URI
19
+ import java.util.*
17
20
18
21
open class SubprojectExtension (val project : Project ) {
19
22
fun init (archiveBase : String , group : String , version : String ) {
23
+ loadSecrets()
24
+
20
25
setBaseProperties(archiveBase, group, version)
21
26
setupJava()
22
27
addRepositories()
@@ -154,6 +159,48 @@ open class SubprojectExtension(val project: Project) {
154
159
if (project.hasProperty(" mavendir" )) {
155
160
maven(project.rootProject.file(project.property(" mavendir" ) as String ))
156
161
}
162
+
163
+ // Sets maven credentials if they are provided. This is generally
164
+ // only used for external/remote uploads.
165
+ if (project.hasProperty(" mavenUsername" ) && project.hasProperty(" mavenPassword" ) && project.hasProperty(" mavenURL" )) {
166
+ maven {
167
+ credentials {
168
+ username = project.property(" mavenUsername" ) as String
169
+ password = project.property(" mavenPassword" ) as String
170
+ }
171
+ url = URI .create(project.property(" mavenURL" ) as String )
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ private fun loadSecrets () {
178
+ // Detects the secrets file provided by CI and loads it into the project properties
179
+ if (project.rootProject.hasProperty(" secretFile" )) {
180
+ project.logger.lifecycle(" Automatically loading properties from the secretFile" )
181
+ val secretsFile = project.rootProject.file(project.rootProject.property(" secretFile" ) as String )
182
+
183
+ if (secretsFile.exists() && secretsFile.name.endsWith(" .properties" )) {
184
+ loadProperties(secretsFile)
185
+ }
186
+ }
187
+ }
188
+
189
+ private fun loadProperties (propertyFile : File ) {
190
+ if (propertyFile.exists()) {
191
+ val properties = Properties ().apply { load(propertyFile.inputStream()) }
192
+
193
+ var count = 0
194
+ for (entry in properties.entries) {
195
+ if (entry.key is String ) {
196
+ project.setProperty(entry.key as String , entry.value)
197
+ count++
198
+ }
199
+ }
200
+
201
+ project.logger.lifecycle(" Successfully loaded $count properties" )
202
+ } else {
203
+ project.logger.warn(" The property file ${propertyFile.getName()} could not be loaded. It does not exist." )
157
204
}
158
205
}
159
206
}
0 commit comments