Skip to content

Commit

Permalink
Drop kotlin-dsl plugin (#295)
Browse files Browse the repository at this point in the history
* Drop kotlin-dsl plugin in favour of directly applying Kotlin plugin

Kotlin 1.8.22 has been selected as it's the last version to support Kotlin
API version 1.3 which this plugin uses to support Gradle versions as old as
Gradle 6.2.

* Remove unused function

* Fix warning

* Fix implict lambda parameter shadowing

* Remove unused import

* Remove Kotlin 1.4 stdlib function.

* Add gradle-api to test classpath

* Update tests to remove use of kotlin-dsl

* Use traditional notation to apply Kotlin JVM plugin

Co-authored-by: Róbert Papp <[email protected]>

---------

Co-authored-by: Róbert Papp (TWiStErRob) <[email protected]>
  • Loading branch information
3flex and TWiStErRob authored Jan 18, 2024
1 parent 627c76c commit 1a808e9
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 181 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
`kotlin-dsl`
id("org.jetbrains.kotlin.jvm") version "1.8.22"
id("com.gradle.plugin-publish") version "1.2.1"
id("com.diffplug.spotless") version "6.23.3"
id("com.github.johnrengelman.shadow") version "8.1.1"
Expand Down Expand Up @@ -95,6 +95,8 @@ dependencies {
// but we are running CI on Java 8 in .github/workflows/java-versions.yml.
testImplementation("org.mockito:mockito-junit-jupiter:4.11.0")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")

testImplementation(gradleApi())
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ internal open class DefaultNexusRepositoryContainer @Inject constructor(
sonatype(Action {})

override fun sonatype(action: Action<in NexusRepository>): NexusRepository = create("sonatype") {
nexusUrl.set(URI.create("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(URI.create("https://oss.sonatype.org/content/repositories/snapshots/"))
action.execute(this)
it.nexusUrl.set(URI.create("https://oss.sonatype.org/service/local/"))
it.snapshotRepositoryUrl.set(URI.create("https://oss.sonatype.org/content/repositories/snapshots/"))
action.execute(it)
}

override fun configure(configureClosure: Closure<*>): NamedDomainObjectContainer<NexusRepository> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Nested
import org.gradle.kotlin.dsl.domainObjectContainer
import org.gradle.kotlin.dsl.newInstance
import java.time.Duration

abstract class NexusPublishExtension(objects: ObjectFactory) {
Expand All @@ -48,8 +46,8 @@ abstract class NexusPublishExtension(objects: ObjectFactory) {
}

val repositories: NexusRepositoryContainer = objects.newInstance(
DefaultNexusRepositoryContainer::class,
objects.domainObjectContainer(NexusRepository::class)
DefaultNexusRepositoryContainer::class.java,
objects.domainObjectContainer(NexusRepository::class.java)
)

fun repositories(action: Action<in NexusRepositoryContainer>) {
Expand Down
278 changes: 130 additions & 148 deletions src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import java.net.URI
import kotlin.reflect.KClass

abstract class NexusRepository(@Input val name: String) {

Expand Down Expand Up @@ -65,8 +64,8 @@ abstract class NexusRepository(@Input val name: String) {
ivyPatternLayout.set(action)
}

enum class PublicationType(internal val gradleType: KClass<out Publication>, internal val publishTaskType: KClass<out DefaultTask>) {
MAVEN(MavenPublication::class, PublishToMavenRepository::class),
IVY(IvyPublication::class, PublishToIvyRepository::class)
enum class PublicationType(internal val gradleType: Class<out Publication>, internal val publishTaskType: Class<out DefaultTask>) {
MAVEN(MavenPublication::class.java, PublishToMavenRepository::class.java),
IVY(IvyPublication::class.java, PublishToIvyRepository::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StagingRepositoryTransitioner(val nexusClient: NexusClient, val retrier: A
private fun assertRepositoryInDesiredState(repository: StagingRepository, vararg desiredStates: StagingRepository.State) {
if (repository.state !in desiredStates) {
throw RepositoryTransitionException(
"Staging repository is not in desired state ${desiredStates.contentToString()}: $repository. It is unexpected. Please check " +
"Staging repository is not in desired state ${desiredStates.contentDeepToString()}: $repository. It is unexpected. Please check " +
"the Nexus logs using its web interface - it can be caused by validation rules violation (e.g. publishing artifacts with the " +
"same version again). If not, please report it to https://github.com/gradle-nexus/publish-plugin/issues/ with the '--info' logs."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
Expand Down Expand Up @@ -68,8 +64,8 @@ class TaskOrchestrationTest {
internal fun `transitioning task should not run after non-related publish`(transitioningTaskName: String) {
// given
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("myNexus")
project.extensions.configure(NexusPublishExtension::class.java) {
it.repositories.create("myNexus")
}
// expect
assertGivenTaskMustNotRunAfterAnother(transitioningTaskName, "publishToMyNexus")
Expand Down Expand Up @@ -105,8 +101,8 @@ class TaskOrchestrationTest {
)
internal fun `simplified task without repository name should be available but trigger nothing if no repositories are configured`(simplifiedTaskName: String) {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.clear()
project.extensions.configure(NexusPublishExtension::class.java) {
it.repositories.clear()
}

val simplifiedTasks = project.getTasksByName(simplifiedTaskName, true)
Expand All @@ -124,8 +120,8 @@ class TaskOrchestrationTest {
)
internal fun `simplified task without repository name should depend on all normal tasks (created one per defined repository)`(simplifiedTaskName: String, sonatypeTaskName: String, otherNexusTaskName: String) {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
project.extensions.configure(NexusPublishExtension::class.java) {
it.repositories.create("otherNexus")
}

val simplifiedTasks = getJustOneTaskByNameOrFail(simplifiedTaskName)
Expand All @@ -146,8 +142,8 @@ class TaskOrchestrationTest {
)
internal fun `description of simplified task contains names of all defined Nexus instances`(simplifiedTaskName: String) {
initSingleProjectWithDefaultConfiguration()
project.extensions.configure<NexusPublishExtension> {
repositories.create("otherNexus")
project.extensions.configure(NexusPublishExtension::class.java) {
it.repositories.create("otherNexus")
}

val simplifiedTasks = getJustOneTaskByNameOrFail(simplifiedTaskName)
Expand All @@ -158,15 +154,15 @@ class TaskOrchestrationTest {
}

private fun initSingleProjectWithDefaultConfiguration() {
project.apply(plugin = "java")
project.apply(plugin = "maven-publish")
project.apply<NexusPublishPlugin>()
project.extensions.configure<NexusPublishExtension> {
repositories.sonatype()
project.pluginManager.apply("java")
project.pluginManager.apply("maven-publish")
project.pluginManager.apply(NexusPublishPlugin::class.java)
project.extensions.configure(NexusPublishExtension::class.java) {
it.repositories.sonatype()
}
project.extensions.configure<PublishingExtension> {
publications.create<MavenPublication>("mavenJava") {
from(project.components["java"])
project.extensions.configure(PublishingExtension::class.java) {
it.publications.create("mavenJava", MavenPublication::class.java) { publication ->
publication.from(project.components.getByName("java"))
}
}
}
Expand Down

0 comments on commit 1a808e9

Please sign in to comment.