Skip to content

Commit

Permalink
forUseAtConfigurationTime compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Jul 18, 2023
1 parent 0a3ba20 commit fc62497
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class NexusPublishPlugin : Plugin<Project> {
stagingRepositoryId.convention(registryService.map { it.registry[repository.get().name].stagingRepositoryId })
}
extension.repositories.all {
username.convention(rootProject.providers.gradleProperty("${name}Username"))
password.convention(rootProject.providers.gradleProperty("${name}Password"))
username.convention(rootProject.providers.gradleProperty("${name}Username").forUseAtConfigurationTimeCompat())
password.convention(rootProject.providers.gradleProperty("${name}Password").forUseAtConfigurationTimeCompat())
publicationType.convention(PublicationType.MAVEN)
configureRepositoryTasks(rootProject.tasks, extension, this, registryService)
}
Expand Down Expand Up @@ -380,3 +380,17 @@ private inline fun <reified T : Any> Project.theExtension(): T =
this.extensions.findByType(it)
?: error("The plugin cannot be applied without the publishing plugin")
}

private fun <T> Provider<T>.forUseAtConfigurationTimeCompat(): Provider<T> =
if (GradleVersion.current() < GradleVersion.version("6.5")) {
// Gradle < 6.5 doesn't have this function.
this
} else if (GradleVersion.current() < GradleVersion.version("7.4")) {
// Gradle 6.5 - 7.3 requires this function to be called.
@Suppress("DEPRECATION")
this.forUseAtConfigurationTime()
} else {
// Gradle >= 7.4 deprecated this function in favor of not calling it (became no-op, and will eventually nag).
// https://docs.gradle.org/current/userguide/upgrading_version_7.html#for_use_at_configuration_time_deprecation
this
}

0 comments on commit fc62497

Please sign in to comment.