Gradle is always so extra

- Set secret properties using project.extra
- Improve logging when loading secrets
- Log when adding the maven specified in secrets
This commit is contained in:
Jozufozu 2025-01-26 17:20:24 -08:00
parent 0288b37b22
commit 8d53f99956

View file

@ -163,6 +163,8 @@ open class SubprojectExtension(val project: Project) {
// Sets maven credentials if they are provided. This is generally // Sets maven credentials if they are provided. This is generally
// only used for external/remote uploads. // only used for external/remote uploads.
if (project.hasProperty("mavenUsername") && project.hasProperty("mavenPassword") && project.hasProperty("mavenURL")) { if (project.hasProperty("mavenUsername") && project.hasProperty("mavenPassword") && project.hasProperty("mavenURL")) {
project.logger.lifecycle("Adding maven from secrets")
maven { maven {
credentials { credentials {
username = project.property("mavenUsername") as String username = project.property("mavenUsername") as String
@ -177,10 +179,11 @@ open class SubprojectExtension(val project: Project) {
private fun loadSecrets() { private fun loadSecrets() {
// Detects the secrets file provided by CI and loads it into the project properties // Detects the secrets file provided by CI and loads it into the project properties
if (project.rootProject.hasProperty("secretFile")) { 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) val secretsFile = project.rootProject.file(project.rootProject.property("secretFile") as String)
if (secretsFile.exists() && secretsFile.name.endsWith(".properties")) { if (secretsFile.exists() && secretsFile.name.endsWith(".properties")) {
project.logger.lifecycle("Loading secrets")
loadProperties(secretsFile) loadProperties(secretsFile)
} }
} }
@ -193,14 +196,14 @@ open class SubprojectExtension(val project: Project) {
var count = 0 var count = 0
for (entry in properties.entries) { for (entry in properties.entries) {
if (entry.key is String) { if (entry.key is String) {
project.setProperty(entry.key as String, entry.value) project.extra[entry.key as String] = entry.value as String
count++ count++
} }
} }
project.logger.lifecycle("Successfully loaded $count properties") project.logger.lifecycle("Loaded $count properties")
} else { } 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")
} }
} }
} }