love.forte.gradle.common.publication.configure.NexusPublications.kt Maven / Gradle / Ivy
package love.forte.gradle.common.publication.configure
import io.github.gradlenexus.publishplugin.NexusRepositoryContainer
import love.forte.gradle.common.core.project.ProjectDetail
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import java.time.Duration
/**
* Retrieves the [nexusPublishing][io.github.gradlenexus.publishplugin.NexusPublishExtension] extension.
*/
val Project.nexusPublishingExtension: io.github.gradlenexus.publishplugin.NexusPublishExtension
get() =
(this as org.gradle.api.plugins.ExtensionAware).extensions.getByName("nexusPublishing") as io.github.gradlenexus.publishplugin.NexusPublishExtension
/**
* Configures the [nexusPublishing][io.github.gradlenexus.publishplugin.NexusPublishExtension] extension.
*/
fun Project.nexusPublishingExtension(configure: Action): Unit =
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("nexusPublishing", configure)
fun Project.nexusPublishConfig(configure: NexusPublishConfigExtension.() -> Unit) {
val config = NexusPublishConfigExtension().also(configure)
nexusPublishingExtension {
val pd = config.projectDetail
it.packageGroup.set(pd.group)
it.repositoryDescription.set(pd.description)
val useStagingProvider = config.useStaging
if (useStagingProvider != null) {
it.useStaging.set(useStagingProvider)
}
it.transitionCheckOptions { opt ->
opt.maxRetries.set(config.transitionCheckMaxRetries)
opt.delayBetween.set(config.transitionCheckDelayBetween)
}
it.repositories(config.repositoriesConfig::invoke)
config.andThen(it)
}
}
class NexusPublishConfigExtension {
lateinit var projectDetail: ProjectDetail
var useStaging: Provider? = null
var transitionCheckMaxRetries: Int = 100
var transitionCheckDelayBetween: Duration = Duration.ofSeconds(5)
var repositoriesConfig: NexusRepositoryContainer.() -> Unit = {}
var andThen: io.github.gradlenexus.publishplugin.NexusPublishExtension.() -> Unit = {}
}