diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/CloudArtifactRegistry.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/CloudArtifactRegistry.kt index 7c11bbcd..67716d89 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/CloudArtifactRegistry.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/CloudArtifactRegistry.kt @@ -51,6 +51,7 @@ import org.gradle.api.Project * Ordering said hooks is a non-trivial operation and the result is usually quite fragile. * Thus, we choose to do this small piece of configuration manually. */ +@Suppress("ConstPropertyName") // https://bit.ly/kotlin-prop-names internal object CloudArtifactRegistry { private const val spineRepoLocation = "https://europe-maven.pkg.dev/spine-event-engine" diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/CustomPublicationHandler.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/CustomPublicationHandler.kt index 13b86386..152455dc 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/CustomPublicationHandler.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/CustomPublicationHandler.kt @@ -46,13 +46,25 @@ import org.gradle.api.publish.maven.MavenPublication * the [standard][org.gradle.api.publish.maven.MavenPublication] publication, and custom ones. * To have both standard and custom publications, please specify custom artifact IDs or * classifiers for each custom publication. + * + * @see StandardJavaPublicationHandler */ -internal class CustomPublicationHandler(project: Project, destinations: Set) : - PublicationHandler(project, destinations) { +internal class CustomPublicationHandler private constructor( + project: Project, + destinations: Set +) : PublicationHandler(project, destinations) { override fun handlePublications() { project.publications.forEach { (it as MavenPublication).copyProjectAttributes() } } + + companion object : HandlerFactory() { + override fun create( + project: Project, + destinations: Set, + vararg params: Any + ): CustomPublicationHandler = CustomPublicationHandler(project, destinations) + } } diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublicationHandler.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublicationHandler.kt index 03848a9d..ce25f513 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublicationHandler.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublicationHandler.kt @@ -42,43 +42,64 @@ private const val MAVEN_PUBLISH = "maven-publish" /** * Abstract base for handlers of publications in a project * with [spinePublishing] settings declared. + * + * @param project The project to which the handler is applied. + * @param destinations The repositories for publishing artifacts of this project. + * In a multi-module project the destinations can be re-defined by + * specifying custom values in + * the [`spinePublishing`][io.spine.gradle.publish.SpinePublishing.destinations] + * extension applied to the subproject. */ internal sealed class PublicationHandler( protected val project: Project, - private val destinations: Set + protected var destinations: Set ) { /** - * Tells if this publication handler already [applied][apply]. - * - * This safeguard is needed because we call the [apply] method - * under [Project.afterEvaluate] block, which could be called more than once. - * This flag helps to ensure that we call the [doApply] only once, thus - * avoiding repeated calls of the publication settings code. + * Remembers if the [apply] function was called by this handler. */ - private var applied = false + private var applied: Boolean = false - fun apply() { - synchronized(this) { - if (applied) { - return@synchronized - } - doApply() - this.applied = true + /** + * Overwrites the [destinations] property with the given set. + */ + fun publishTo(alternativeDestinations: Set) { + if (alternativeDestinations.isEmpty()) { + project.logger.info( + "The project ${project.path} is not going to be published because" + + " the publication handler `${this@PublicationHandler}`" + + " got an empty set of new `destinations`." + ) } + destinations = alternativeDestinations } /** * Configures the publication of the associated [project]. */ - private fun doApply() { - project.run { - if (!hasCustomPublishing) { - apply(plugin = MAVEN_PUBLISH) + fun apply() { + synchronized(project) { + if (applied) { + return } - pluginManager.withPlugin(MAVEN_PUBLISH) { - handlePublications() - registerDestinations() - configurePublishTask(destinations) + project.run { + // We apply the `maven-publish` plugin for modules with standard + // publishing automatically because they don't need custom DSL + // in their `build.gradle.kts` files. + // All the job is done by the `SpinePublishing` extension and + // `StandardPublicationHandler` instance associated with this project. + if (!hasCustomPublishing) { + apply(plugin = MAVEN_PUBLISH) + } + // And we do not apply the plugin for modules with custom publishing + // because they will need the `maven-publish` DSL to tune the publishing. + // Therefore, we only arrange the execution of our code when the plugin + // is applied. + pluginManager.withPlugin(MAVEN_PUBLISH) { + handlePublications() + registerDestinations() + configurePublishTask(destinations) + applied = true + } } } } @@ -131,6 +152,66 @@ internal sealed class PublicationHandler( } } } + + /** + * The abstract base for factories producing instances of classes + * derived from [io.spine.gradle.publish.PublicationHandler]. + * + * The factory maintains associations between a path of the project to + * its publication handler. + * + * If the handler already exists, its settings are updated when + * the [serving] factory method is called. + * + * Otherwise, a new handler is created and associated with the project. + * + * @param H The type of the publication handlers produced by this repository. + * @see serving + */ + abstract class HandlerFactory { + + /** + * Maps a project path to the associated handler, if available. + */ + private val handlers = mutableMapOf() + + /** + * Obtains an instance of [PublicationHandler] for the given project. + * + * If the handler for the given [project] was already created, the handler + * gets new [destinations], [overwriting][publishTo] previously specified. + * + * @return the handler for the given project which would handle publishing to + * the specified [destinations]. + */ + fun serving(project: Project, destinations: Set, vararg params: Any): H { + synchronized(handlers) { + val path = project.path + var handler = handlers[path] + if (handler == null) { + handler = create(project, destinations, *params) + handlers[path] = handler + } else { + handler.publishTo(destinations) + } + return handler + } + } + + /** + * Creates a new publication handler for the given project. + * + * @param project The project to which the handler applies. + * @param destinations The repositories for publishing artifacts of this project. + * @param params Optional parameters to be passed as constructor parameters for + * classes of the type [H]. + */ + protected abstract fun create( + project: Project, + destinations: Set, + vararg params: Any + ): H + } } /** diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublishingExts.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublishingExts.kt index 4bf03e65..0a24b56b 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublishingExts.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/PublishingExts.kt @@ -58,6 +58,13 @@ internal val Project.publishingExtension: PublishingExtension internal val Project.publications: PublicationContainer get() = publishingExtension.publications +/** + * Obtains an instance, if available, of [SpinePublishing] extension + * applied to this project. + */ +internal val Project.localSpinePublishing: SpinePublishing? + get() = extensions.findByType() + /** * Obtains [SpinePublishing] extension from this [Project]. * @@ -66,7 +73,7 @@ internal val Project.publications: PublicationContainer */ internal val Project.spinePublishing: SpinePublishing get() { - val local = this.extensions.findByType() + val local = localSpinePublishing if (local != null) { return local } diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/SpinePublishing.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/SpinePublishing.kt index d07a0f20..9dc7d7c9 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/SpinePublishing.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/SpinePublishing.kt @@ -134,8 +134,8 @@ import org.gradle.kotlin.dsl.findByType * and can be disabled via [SpinePublishing.protoJar]. * * 3. [javadocJar] — Javadoc, generated upon Java sources from the `main` source set. - * If Javadoc for Kotlin is also needed, apply the Dokka plugin. It tunes `javadoc` task to generate - * docs upon Kotlin sources as well. + * If Javadoc for Kotlin is also needed, apply the Dokka plugin. + * It tunes the `javadoc` task to generate docs upon Kotlin sources as well. * * 4. [dokkaKotlinJar] — documentation generated by Dokka for Kotlin and Java sources * using the Kotlin API mode. @@ -147,6 +147,7 @@ import org.gradle.kotlin.dsl.findByType * of the `test` source set. Use [SpinePublishing.testJar] to enable its publishing. * * @see [artifacts] + * @see SpinePublishing */ fun Project.spinePublishing(block: SpinePublishing.() -> Unit) { apply() @@ -161,7 +162,16 @@ fun Project.spinePublishing(block: SpinePublishing.() -> Unit) { } /** - * A Gradle extension for setting up publishing of spine modules using `maven-publish` plugin. + * A Gradle extension for setting up publishing of modules of Spine SDK modules + * using `maven-publish` plugin. + * + * ### Implementation Note + * + * This extension is overloaded with responsibilities. + * It basically does what an extension AND a Gradle plugin would normally do. + * + * We [should introduce a plugin class](https://github.com/SpineEventEngine/config/issues/562) + * and move the code related to creating tasks or setting dependencies between them into the plugin. * * @param project The project in which the extension is opened. By default, this project will be * published as long as a [set][modules] of modules to publish is not specified explicitly. @@ -240,9 +250,10 @@ open class SpinePublishing(private val project: Project) { * )} * ``` * - * Empty by default. + * If the property is not initialized, the destinations will be taken from + * the parent project. */ - var destinations: Set = emptySet() + lateinit var destinations: Set /** * A prefix to be added before the name of each artifact. @@ -318,8 +329,8 @@ open class SpinePublishing(private val project: Project) { * } * ``` * - * The resulting artifact is available under "test" classifier. For example, - * in Gradle 7+, one could depend on it like this: + * The resulting artifact is available under the "test" classifier. + * For example, in Gradle 7+, one could depend on it like this: * * ``` * implementation("io.spine:spine-client:$version@test") @@ -419,16 +430,36 @@ open class SpinePublishing(private val project: Project) { */ private fun Project.setUpPublishing(jarFlags: JarFlags) { val customPublishing = modulesWithCustomPublishing.contains(name) || customPublishing + val destinations = project.publishTo() val handler = if (customPublishing) { - CustomPublicationHandler(project, destinations) + CustomPublicationHandler.serving(project, destinations) } else { - StandardJavaPublicationHandler(project, jarFlags, destinations) + StandardJavaPublicationHandler.serving(project, destinations, jarFlags) } afterEvaluate { handler.apply() } } + /** + * Obtains the set of repositories for publishing. + * + * If there is a local instance of [io.spine.gradle.publish.SpinePublishing] extension, + * the [destinations] are obtained from this instance. + * Otherwise, the function attempts to obtain it from a [parent project][Project.getParent]. + * If there is no a parent project, an empty set is returned. + * + * The normal execution should end up at the root project of a multi-module project + * if there are no custom destinations specified by the local extension. + */ + private fun Project.publishTo(): Set { + val ext = localSpinePublishing + if (ext != null && ext::destinations.isInitialized) { + return destinations + } + return parent?.publishTo() ?: emptySet() + } + /** * Obtains an artifact ID for the given project. * @@ -447,8 +478,11 @@ open class SpinePublishing(private val project: Project) { private fun ensureProtoJarExclusionsArePublished() { val nonPublishedExclusions = protoJar.exclusions.minus(modules) if (nonPublishedExclusions.isNotEmpty()) { - throw IllegalStateException("One or more modules are marked as `excluded from proto " + - "JAR publication`, but they are not even published: $nonPublishedExclusions") + error( + "One or more modules are marked as" + + " `excluded from proto JAR publication`," + + " but they are not even published: $nonPublishedExclusions." + ) } } @@ -472,7 +506,7 @@ open class SpinePublishing(private val project: Project) { /** * Ensures that publishing of a module is configured only from a single place. * - * We allow configuration of publishing from two places - a root project and module itself. + * We allow configuration of publishing from two places - a root project and the module itself. * Here we verify that publishing of a module is not configured in both places simultaneously. */ private fun ensureModulesNotDuplicated() { diff --git a/buildSrc/src/main/kotlin/io/spine/gradle/publish/StandardJavaPublicationHandler.kt b/buildSrc/src/main/kotlin/io/spine/gradle/publish/StandardJavaPublicationHandler.kt index 3b5b731a..06d78c10 100644 --- a/buildSrc/src/main/kotlin/io/spine/gradle/publish/StandardJavaPublicationHandler.kt +++ b/buildSrc/src/main/kotlin/io/spine/gradle/publish/StandardJavaPublicationHandler.kt @@ -40,25 +40,45 @@ import org.gradle.kotlin.dsl.create * A publication has a name and consists of one or more artifacts plus information about * those artifacts – the metadata. * - * An instance of this class represents [org.gradle.api.publish.maven.MavenPublication] named "mavenJava". It is generally - * accepted that a publication with this name contains a Java project published to one or - * more Maven repositories. + * An instance of this class represents + * [MavenPublication][org.gradle.api.publish.maven.MavenPublication] + * named [`"mavenJava"`][PUBLICATION_NAME]. + * It is generally accepted that a publication with this name contains a Java project + * published to one or more Maven repositories. * * By default, only a jar with the compilation output of `main` source set and its * metadata files are published. Other artifacts are specified through the - * [constructor parameter][jarFlags]. Please, take a look on [specifyArtifacts] for additional info. + * [constructor parameter][jarFlags]. + * Please take a look on [specifyArtifacts] for additional info. * * @param jarFlags The flags for additional JARs published along with the compilation output. * @param destinations Maven repositories to which the produced artifacts will be sent. * @see * The Maven Publish Plugin | Publications + * @see CustomPublicationHandler */ -internal class StandardJavaPublicationHandler( +internal class StandardJavaPublicationHandler private constructor( project: Project, private val jarFlags: JarFlags, destinations: Set, ) : PublicationHandler(project, destinations) { + companion object : HandlerFactory() { + + /** + * The name of the publication created by [StandardJavaPublicationHandler]. + */ + const val PUBLICATION_NAME = "mavenJava" + + override fun create( + project: Project, + destinations: Set, + vararg params: Any + ): StandardJavaPublicationHandler { + return StandardJavaPublicationHandler(project, params[0] as JarFlags, destinations) + } + } + /** * Creates a new `"mavenJava"` [MavenPublication][org.gradle.api.publish.maven.MavenPublication] * in the [project] associated with this publication handler. @@ -66,7 +86,7 @@ internal class StandardJavaPublicationHandler( override fun handlePublications() { val jars = project.artifacts(jarFlags) val publications = project.publications - publications.create("mavenJava") { + publications.create(PUBLICATION_NAME) { copyProjectAttributes() specifyArtifacts(jars) } diff --git a/dependencies.md b/dependencies.md index e6129636..86568b9b 100644 --- a/dependencies.md +++ b/dependencies.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.tools:spine-gradle-plugin-api:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-gradle-plugin-api:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -879,12 +879,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:41 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-gradle-plugin-api-test-fixtures:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-gradle-plugin-api-test-fixtures:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.18.3. @@ -1267,12 +1267,12 @@ This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:41 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-gradle-root-plugin:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-gradle-root-plugin:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : org.jetbrains. **Name** : annotations. **Version** : 26.0.2. @@ -2060,12 +2060,12 @@ This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:41 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:intellij-platform:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:intellij-platform:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -2574,12 +2574,12 @@ This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:41 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:intellij-platform-java:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:intellij-platform-java:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -3860,12 +3860,12 @@ This report was generated on **Thu Apr 24 20:24:32 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:41 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-plugin-api:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-plugin-api:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : org.jetbrains. **Name** : annotations. **Version** : 26.0.2. @@ -4601,12 +4601,12 @@ This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:42 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-plugin-base:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-plugin-base:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -5470,12 +5470,12 @@ This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:42 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-plugin-testlib:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-plugin-testlib:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : com.google.auto.value. **Name** : auto-value-annotations. **Version** : 1.10.2. @@ -6442,12 +6442,12 @@ This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:42 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-psi:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-psi:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -7541,12 +7541,12 @@ This report was generated on **Thu Apr 24 20:24:33 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:34 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:42 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-psi-java:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-psi-java:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : be.cyberelf.nanoxml. **Name** : nanoxml. **Version** : 2.2.3. @@ -9370,12 +9370,12 @@ This report was generated on **Thu Apr 24 20:24:34 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:34 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Fri Apr 25 20:04:43 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:spine-tool-base:2.0.0-SNAPSHOT.308` +# Dependencies of `io.spine.tools:spine-tool-base:2.0.0-SNAPSHOT.309` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -10260,4 +10260,4 @@ This report was generated on **Thu Apr 24 20:24:34 WEST 2025** using [Gradle-Lic The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Apr 24 20:24:34 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file +This report was generated on **Fri Apr 25 20:04:43 WEST 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/plugin-base/src/main/kotlin/io/spine/tools/gradle/protobuf/ProtobufTaskName.kt b/plugin-base/src/main/kotlin/io/spine/tools/gradle/protobuf/ProtobufTaskName.kt new file mode 100644 index 00000000..e8c65987 --- /dev/null +++ b/plugin-base/src/main/kotlin/io/spine/tools/gradle/protobuf/ProtobufTaskName.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2025, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and/or binary forms, with or without + * modification, must retain the above copyright notice and the following + * disclaimer. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.spine.tools.gradle.protobuf + +import io.spine.tools.code.SourceSetName +import io.spine.tools.code.SourceSetName.Companion.main +import io.spine.tools.code.SourceSetName.Companion.test +import io.spine.tools.gradle.task.TaskName +import io.spine.tools.gradle.task.TaskWithSourceSetName + +/** + * Names of Gradle tasks defined by the Protobuf Gradle plugin. + * + * ### API Note + * + * The class is made open only to support package migration of + * [io.spine.tools.gradle.task.ProtobufTaskName], which is deprecated in favor of + * this one. Once the deprecated class is removed, this class should become final. + * + * @see Protobuf Gradle plugin + */ +public open class ProtobufTaskName(value: String, ssn: SourceSetName) : + TaskWithSourceSetName(value, ssn) { + + public companion object { + + /** + * Obtains a name of the `generateProto` task for the specified source set. + */ + @JvmStatic + public fun generateProto(ssn: SourceSetName): TaskName = + ProtobufTaskName("generate${ssn.toInfix()}Proto", ssn) + + /** + * Generates production code from Protobuf. + * + * Note that this task is not a public API of the plugin. + * Users should be conscious and cautious when depending on it. + */ + @JvmField + public val generateProto: TaskName = generateProto(main) + + /** + * Generates test code from Protobuf. + * + * Note that this task is not a public API of the plugin. + * Users should be conscious and cautious when depending on it. + */ + @JvmField + public val generateTestProto: TaskName = generateProto(test) + } +} diff --git a/plugin-base/src/main/kotlin/io/spine/tools/gradle/task/ProtobufTaskName.kt b/plugin-base/src/main/kotlin/io/spine/tools/gradle/task/ProtobufTaskName.kt index f7a1686b..9435fc2b 100644 --- a/plugin-base/src/main/kotlin/io/spine/tools/gradle/task/ProtobufTaskName.kt +++ b/plugin-base/src/main/kotlin/io/spine/tools/gradle/task/ProtobufTaskName.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022, TeamDev. All rights reserved. + * Copyright 2025, TeamDev. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Redistribution and use in source and/or binary forms, with or without * modification, must retain the above copyright notice and the following @@ -23,28 +23,49 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package io.spine.tools.gradle.task import io.spine.tools.code.SourceSetName import io.spine.tools.code.SourceSetName.Companion.main import io.spine.tools.code.SourceSetName.Companion.test +import io.spine.tools.gradle.protobuf.ProtobufTaskName + +private const val NEW_CLASS_NAME = "io.spine.tools.gradle.protobuf.ProtobufTaskName" + +private const val IMPORT = "NEW_CLASS_NAME" /** * Names of Gradle tasks defined by the Protobuf Gradle plugin. * * @see Protobuf Gradle plugin */ +@Deprecated( + message = "Please use `$NEW_CLASS_NAME`.", + replaceWith = ReplaceWith( + "ProtobufTaskName", + imports = [IMPORT] + ) +) public class ProtobufTaskName(value: String, ssn: SourceSetName) : - TaskWithSourceSetName(value, ssn) { + ProtobufTaskName(value, ssn) { public companion object { /** * Obtains a name of the `generateProto` task for the specified source set. */ + @Deprecated( + message = + "Please use `$NEW_CLASS_NAME.generateProto` instead.", + replaceWith = ReplaceWith( + "ProtobufTaskName.generateProto", + imports = [IMPORT] + ) + ) @JvmStatic public fun generateProto(ssn: SourceSetName): TaskName = - ProtobufTaskName("generate${ssn.toInfix()}Proto", ssn) + ProtobufTaskName.generateProto(ssn) /** * Generates production code from Protobuf. @@ -52,8 +73,16 @@ public class ProtobufTaskName(value: String, ssn: SourceSetName) : * Note that this task is not a public API of the plugin. * Users should be conscious and cautious when depending on it. */ + @Deprecated( + message = + "Please use `$NEW_CLASS_NAME.generateProto` instead.", + replaceWith = ReplaceWith( + "ProtobufTaskName.generateProto", + imports = [IMPORT] + ) + ) @JvmField - public val generateProto: TaskName = generateProto(main) + public val generateProto: TaskName = ProtobufTaskName.generateProto(main) /** * Generates test code from Protobuf. @@ -61,7 +90,15 @@ public class ProtobufTaskName(value: String, ssn: SourceSetName) : * Note that this task is not a public API of the plugin. * Users should be conscious and cautious when depending on it. */ + @Deprecated( + message = + "Please use `$NEW_CLASS_NAME.generateTestProto` instead.", + replaceWith = ReplaceWith( + "ProtobufTaskName.generateTestProto", + imports = [IMPORT] + ) + ) @JvmField - public val generateTestProto: TaskName = generateProto(test) + public val generateTestProto: TaskName = ProtobufTaskName.generateProto(test) } } diff --git a/plugin-base/src/test/java/io/spine/tools/gradle/given/StubProject.java b/plugin-base/src/test/java/io/spine/tools/gradle/given/StubProject.java index b38f6076..e6de4938 100644 --- a/plugin-base/src/test/java/io/spine/tools/gradle/given/StubProject.java +++ b/plugin-base/src/test/java/io/spine/tools/gradle/given/StubProject.java @@ -32,8 +32,8 @@ import java.io.File; -import static io.spine.tools.gradle.task.ProtobufTaskName.generateProto; -import static io.spine.tools.gradle.task.ProtobufTaskName.generateTestProto; +import static io.spine.tools.gradle.protobuf.ProtobufTaskName.generateProto; +import static io.spine.tools.gradle.protobuf.ProtobufTaskName.generateTestProto; import static org.gradle.internal.impldep.com.google.common.base.Preconditions.checkNotNull; /** diff --git a/plugin-base/src/test/kotlin/io/spine/tools/gradle/task/GradleTaskBuilderSpec.kt b/plugin-base/src/test/kotlin/io/spine/tools/gradle/task/GradleTaskBuilderSpec.kt index e7d28a0a..979ac838 100644 --- a/plugin-base/src/test/kotlin/io/spine/tools/gradle/task/GradleTaskBuilderSpec.kt +++ b/plugin-base/src/test/kotlin/io/spine/tools/gradle/task/GradleTaskBuilderSpec.kt @@ -37,8 +37,8 @@ import io.spine.tools.gradle.task.GivenTaskName.preClean import io.spine.tools.gradle.task.GivenTaskName.verifyModel import io.spine.tools.gradle.task.JavaTaskName.Companion.classes import io.spine.tools.gradle.task.JavaTaskName.Companion.compileJava -import io.spine.tools.gradle.task.ProtobufTaskName.Companion.generateProto -import io.spine.tools.gradle.task.ProtobufTaskName.Companion.generateTestProto +import io.spine.tools.gradle.protobuf.ProtobufTaskName.Companion.generateProto +import io.spine.tools.gradle.protobuf.ProtobufTaskName.Companion.generateTestProto import io.spine.tools.gradle.testing.GradleProject import io.spine.tools.gradle.testing.NoOp import java.io.File @@ -156,6 +156,6 @@ internal class GradleTaskBuilderSpec { inputs.files.files ) inputFiles shouldHaveSize 1 - inputFiles[0]!!.canonicalFile shouldBe input.canonicalFile + inputFiles[0].canonicalFile shouldBe input.canonicalFile } } diff --git a/pom.xml b/pom.xml index 2c22a87a..16009933 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject. --> io.spine.tools tool-base -2.0.0-SNAPSHOT.308 +2.0.0-SNAPSHOT.309 2015 diff --git a/tool-base/build.gradle.kts b/tool-base/build.gradle.kts index 7e95809f..844345c1 100644 --- a/tool-base/build.gradle.kts +++ b/tool-base/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024, TeamDev. All rights reserved. + * Copyright 2025, TeamDev. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -164,14 +164,3 @@ fun Project.applyGeneratedDirectories(generatedDir: String) { } } } - -/** - * Make the `sourcesJar` task accept duplicated input which seems to occur - * somewhere inside either ProtoData or McJava. - */ -project.afterEvaluate { - val sourcesJar by tasks.getting { - this as Jar - duplicatesStrategy = DuplicatesStrategy.INCLUDE - } -} diff --git a/version.gradle.kts b/version.gradle.kts index 867681e1..8daa96e0 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -24,4 +24,4 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -val versionToPublish: String by extra("2.0.0-SNAPSHOT.308") +val versionToPublish: String by extra("2.0.0-SNAPSHOT.309")