Skip to content

Commit

Permalink
fix(logging): warn only if publishing tasks get executed
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Nov 27, 2021
1 parent cae4c4e commit d5cf58d
Showing 1 changed file with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ fun Project.configureRepository(repoToConfigure: Repository) {
mavenArtifactRepository.credentials { credentials ->
credentials.username = repoToConfigure.user.orNull
credentials.password = repoToConfigure.password.orNull
credentials.username ?: project.logger.warn(
"No username configured for repository {} at {}.",
repoToConfigure.name,
repoToConfigure.url,
)
credentials.password ?: project.logger.warn(
"No password configured for user {} on repository {} at {}.",
repoToConfigure.user,
repoToConfigure.name,
repoToConfigure.url,
)
}
tasks.withType(PublishToMavenRepository::class) {
if (it.repository == mavenArtifactRepository) {
it.doFirst {
warnIfCredentialsAreMissing(repoToConfigure)
}
}
}
}
}
Expand Down Expand Up @@ -100,6 +96,7 @@ private fun Project.configureNexusRepository(repoToConfigure: Repository, nexusU
}
}
publishTask.doFirst {
warnIfCredentialsAreMissing(repoToConfigure)
publishTask.repository.url = nexus.repoUrl
}
publishTask.publication = publication
Expand All @@ -123,3 +120,21 @@ private fun Project.configureNexusRepository(repoToConfigure: Repository, nexusU
}
}
}

private fun Project.warnIfCredentialsAreMissing(repository: Repository) {
if (repository.user.orNull == null) {
logger.warn(
"No username configured for repository {} at {}.",
repository.name,
repository.url,
)
}
if (repository.password.orNull == null) {
logger.warn(
"No password configured for user {} on repository {} at {}.",
repository.user.orNull,
repository.name,
repository.url,
)
}
}

0 comments on commit d5cf58d

Please sign in to comment.