Skip to content

Commit

Permalink
inject BuildEventsListenerRegistry (#831)
Browse files Browse the repository at this point in the history
* inject BuildEventsListenerRegistry

* ktlint
  • Loading branch information
gabrielittner authored Sep 19, 2024
1 parent 1c20e1f commit 782f06f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.vanniktech.maven.publish.sonatype.DropSonatypeRepositoryTask.Companio
import com.vanniktech.maven.publish.sonatype.ReleaseSonatypeRepositoryTask.Companion.registerReleaseRepository
import com.vanniktech.maven.publish.sonatype.SonatypeRepositoryBuildService.Companion.registerSonatypeRepositoryBuildService
import com.vanniktech.maven.publish.tasks.WorkaroundSignatureType
import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.Incubating
import org.gradle.api.Project
Expand All @@ -14,15 +15,17 @@ import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.build.event.BuildEventsListenerRegistry
import org.gradle.external.javadoc.StandardJavadocDocletOptions
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningPlugin
import org.gradle.plugins.signing.type.pgp.ArmoredSignatureType
import org.gradle.util.GradleVersion
import org.jetbrains.dokka.gradle.DokkaTask

abstract class MavenPublishBaseExtension(
abstract class MavenPublishBaseExtension @Inject constructor(
private val project: Project,
private val buildEventsListenerRegistry: BuildEventsListenerRegistry,
) {
private val sonatypeHost: Property<SonatypeHost> = project.objects.property(SonatypeHost::class.java)
private val signing: Property<Boolean> = project.objects.property(Boolean::class.java)
Expand All @@ -31,7 +34,7 @@ abstract class MavenPublishBaseExtension(
internal val version: Property<String> = project.objects.property(String::class.java)
.convention(project.provider { project.version.toString() })
private val pomFromProperties: Property<Boolean> = project.objects.property(Boolean::class.java)
internal val platform: Property<Platform> = project.objects.property(Platform::class.java)
private val platform: Property<Platform> = project.objects.property(Platform::class.java)

/**
* Sets up Maven Central publishing through Sonatype OSSRH by configuring the target repository. Gradle will then
Expand Down Expand Up @@ -65,6 +68,7 @@ abstract class MavenPublishBaseExtension(
automaticRelease = automaticRelease,
// TODO: stop accessing rootProject https://github.com/gradle/gradle/pull/26635
rootBuildDirectory = project.rootProject.layout.buildDirectory,
buildEventsListenerRegistry = buildEventsListenerRegistry,
)

val configCacheEnabled = project.configurationCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.gradle.api.provider.Provider
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.build.event.BuildEventsListenerRegistry
import org.gradle.configurationcache.extensions.serviceOf
import org.gradle.tooling.events.FailureResult
import org.gradle.tooling.events.FinishEvent
import org.gradle.tooling.events.OperationCompletionListener
Expand Down Expand Up @@ -324,6 +323,7 @@ internal abstract class SonatypeRepositoryBuildService :
repositoryPassword: Provider<String>,
automaticRelease: Boolean,
rootBuildDirectory: Provider<Directory>,
buildEventsListenerRegistry: BuildEventsListenerRegistry,
): Provider<SonatypeRepositoryBuildService> {
val okhttpTimeout = project.providers.gradleProperty("SONATYPE_CONNECT_TIMEOUT_SECONDS")
.map { it.toLong() }
Expand All @@ -343,7 +343,7 @@ internal abstract class SonatypeRepositoryBuildService :
it.parameters.closeTimeoutSeconds.set(closeTimeout)
it.parameters.rootBuildDirectory.set(rootBuildDirectory)
}
project.serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
buildEventsListenerRegistry.onTaskCompletion(service)
return service
}
}
Expand Down

0 comments on commit 782f06f

Please sign in to comment.