@@ -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} '" )
0 commit comments