Skip to content

Commit

Permalink
Gradle is always so extra
Browse files Browse the repository at this point in the history
- Set secret properties using project.extra
- Improve logging when loading secrets
- Log when adding the maven specified in secrets
  • Loading branch information
Jozufozu committed Jan 27, 2025
1 parent 0288b37 commit 8d53f99
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ open class SubprojectExtension(val project: Project) {
// Sets maven credentials if they are provided. This is generally
// only used for external/remote uploads.
if (project.hasProperty("mavenUsername") && project.hasProperty("mavenPassword") && project.hasProperty("mavenURL")) {
project.logger.lifecycle("Adding maven from secrets")

maven {
credentials {
username = project.property("mavenUsername") as String
Expand All @@ -177,10 +179,11 @@ open class SubprojectExtension(val project: Project) {
private fun loadSecrets() {
// Detects the secrets file provided by CI and loads it into the project properties
if (project.rootProject.hasProperty("secretFile")) {
project.logger.lifecycle("Automatically loading properties from the secretFile")
val secretsFile = project.rootProject.file(project.rootProject.property("secretFile") as String)

if (secretsFile.exists() && secretsFile.name.endsWith(".properties")) {
project.logger.lifecycle("Loading secrets")

loadProperties(secretsFile)
}
}
Expand All @@ -193,14 +196,14 @@ open class SubprojectExtension(val project: Project) {
var count = 0
for (entry in properties.entries) {
if (entry.key is String) {
project.setProperty(entry.key as String, entry.value)
project.extra[entry.key as String] = entry.value as String
count++
}
}

project.logger.lifecycle("Successfully loaded $count properties")
project.logger.lifecycle("Loaded $count properties")
} else {
project.logger.warn("The property file ${propertyFile.getName()} could not be loaded. It does not exist.")
project.logger.warn("The property file ${propertyFile.getName()} does not exist")
}
}
}
Expand Down

0 comments on commit 8d53f99

Please sign in to comment.