Skip to content

Commit 52036e3

Browse files
author
mtctx
committed
feat(2.0.2): Fixed issues with vanniktech requiring properties
1 parent f968bf2 commit 52036e3

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/main/kotlin/dev/mtctx/unipub/UniPub.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,31 @@ class UniPub : Plugin<Project> {
4646
description = "Generate a template file for UniPub at $globalPath."
4747
}
4848

49+
50+
val settings =
51+
loadAndValidateSettingsFile(extension, projectPath(target.project.projectDir.absolutePath))
52+
val profile = settings.profiles.find { it.name == extension.profileName }
53+
?: throw GradleException(
54+
"""
55+
Profile '${extension.profileName}' not found in settings file. Please check your settings file and try again.'
56+
Available profiles: ${settings.profiles.joinToString(", ") { it.name }}
57+
""".trimIndent()
58+
)
59+
60+
val usesVanniktechMavenPublish = target.plugins.hasPlugin("com.vanniktech.maven.publish")
61+
if (usesVanniktechMavenPublish) {
62+
target.project.extensions.extraProperties["mavenCentralUsername"] = profile.username
63+
target.project.extensions.extraProperties["mavenCentralPassword"] = profile.password
64+
target.logger.lifecycle("UniPub: Injected Gradle properties for Vanniktech (profile '${profile.name}')")
65+
}
66+
4967
target.tasks.withType(PublishToMavenRepository::class.java).configureEach {
5068
doFirst {
5169
if (repository.url.scheme == "file") return@doFirst
5270

53-
val settings =
54-
loadAndValidateSettingsFile(extension, projectPath(target.project.projectDir.absolutePath))
55-
val profile = settings.profiles.find { it.name == extension.profileName }
56-
?: throw GradleException(
57-
"""
58-
Profile '${extension.profileName}' not found in settings file. Please check your settings file and try again.'
59-
Available profiles: ${settings.profiles.joinToString(", ") { it.name }}
60-
""".trimIndent()
61-
)
62-
6371
repository.credentials {
64-
username = username?.takeIf { it.isNotBlank() && it.isNotEmpty() } ?: profile.username.resolveEnv()
65-
password = password?.takeIf { it.isNotBlank() && it.isNotEmpty() } ?: profile.password.resolveEnv()
66-
72+
username = username?.takeIf { it.isNotBlank() && it.isNotEmpty() } ?: profile.username
73+
password = password?.takeIf { it.isNotBlank() && it.isNotEmpty() } ?: profile.password
6774
}
6875

6976
logger.lifecycle("UniPub: Injected credentials for profile '${profile.name}'")

src/main/kotlin/dev/mtctx/unipub/UniPubSettings.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ data class UniPubSettings(
3232
@Serializable
3333
data class Profile(
3434
@SerialName("name")
35-
private val _name: String,
35+
private val rawName: String,
3636
@SerialName("username")
37-
private val _username: String,
37+
private val rawUsername: String,
3838
@SerialName("password")
39-
private val _password: String
39+
private val rawPassword: String
4040
) {
41-
val name get() = _name.resolveEnv()
42-
val username get() = _username.resolveEnv()
43-
val password get() = _password.resolveEnv()
41+
val name get() = rawName.resolveEnv()
42+
val username get() = rawUsername.resolveEnv()
43+
val password get() = rawPassword.resolveEnv()
4444

4545
init {
4646
require(name.isNotBlank()) { "A profile 'name' cannot be blank in the settings file." }

0 commit comments

Comments
 (0)