Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions dependencies.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ artifactMeta {
}

dependencies {
compileOnly(gradleKotlinDsl())
implementation(Compiler.pluginLib)
implementation(Compiler.params)
implementation(ToolBase.jvmTools)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
package io.spine.tools.core.jvm.gradle.plugins

import io.spine.tools.compiler.gradle.api.CompilerSettings
import io.spine.tools.compiler.gradle.api.Names.GRADLE_PLUGIN_ID
import io.spine.tools.compiler.gradle.api.addUserClasspathDependency
import io.spine.tools.compiler.gradle.api.compilerSettings
import io.spine.tools.compiler.gradle.api.compilerWorkingDir
Expand Down Expand Up @@ -57,8 +56,9 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import io.spine.tools.compiler.plugin.Plugin as CompilerPlugin
import io.spine.tools.compiler.gradle.plugin.Plugin as CompilerGradlePlugin
import org.gradle.kotlin.dsl.apply

/**
* The plugin that configures the Spine Compiler for the associated project.
Expand Down Expand Up @@ -86,7 +86,9 @@ internal class CompilerConfigPlugin : Plugin<Project> {
project.afterEvaluate {
it.configureCompiler()
}
project.pluginManager.apply(GRADLE_PLUGIN_ID)
// Apply the Compiler Gradle Plugin so that we can manipulate the compiler settings.
// We do not want the user to add it manually.
project.apply<CompilerGradlePlugin>()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package io.spine.tools.core.jvm.gradle.plugins

import com.google.protobuf.gradle.ProtobufPlugin
import io.spine.string.simply
import io.spine.tools.core.jvm.VersionHolder
import io.spine.tools.core.jvm.gradle.CoreJvmOptions
Expand All @@ -39,6 +40,7 @@ import io.spine.tools.gradle.DslSpec
import io.spine.tools.gradle.lib.LibraryPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply

/**
* Spine Model Compiler for Java Gradle plugin.
Expand Down Expand Up @@ -76,8 +78,7 @@ public class CoreJvmPlugin : LibraryPlugin<CoreJvmOptions>(
private fun Project.applyProtobufPlugin() {
if (!pluginManager.hasPlugin(ProtobufGradlePlugin.id)) {
// We carry the plugin as a runtime dependency of the fat JAR.
// So it will be available in the build classpath and found by the ID.
pluginManager.apply(ProtobufGradlePlugin.id)
project.apply<ProtobufPlugin>()
}
Comment on lines 78 to 82
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applyProtobufPlugin() applies Protobuf by class (apply<ProtobufPlugin>()) but the surrounding logic still relies on plugin ID checks/callbacks (hasPlugin(ProtobufGradlePlugin.id) here, and withPlugin(ProtobufGradlePlugin.id) in apply). When a plugin is applied by type, Gradle does not reliably associate it with an ID, so the ID-based check/callback may not observe the plugin and applyCoreJvmPlugins() may never run when Protobuf wasn’t already applied by ID. Prefer class-based checks/hooks (e.g., plugins.hasPlugin(ProtobufPlugin::class.java) / plugins.withType(ProtobufPlugin::class.java)) or apply CoreJvm plugins immediately after applying Protobuf.

Copilot uses AI. Check for mistakes.
}

Expand Down Expand Up @@ -105,11 +106,11 @@ private fun Project.createAndApplyPlugins() {
RoutingPlugin()
)
plugins.forEach {
apply(it)
doApply(it)
}
}

private fun Project.apply(plugin: Plugin<Project>) {
private fun Project.doApply(plugin: Plugin<Project>) {
logger.debug { "Applying `${plugin.javaClass.name}` plugin." }
plugin.apply(project)
}
72 changes: 71 additions & 1 deletion plugin-bundle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,57 @@ publishing {
excludeGroup(it, "io.spine.tools")
}

/*
* Add the dependency onto `io.spine.tools:compiler-gradle-plugin`,
* so that CoreJvm Gradle Plugin can add it to a project.
*/
val compilerGradlePlugin = Node(dependencies, "dependency")
compilerGradlePlugin.let {
Node(it, "groupId", "io.spine.tools")
Node(it, "artifactId", "compiler-gradle-plugin")
Node(it, "version", Compiler.version)
Node(it, "scope", "runtime")
}
Node(compilerGradlePlugin, "exclusions").let {
excludeGroup(it, "org.jetbrains.kotlin")
excludeGroup(it, "com.google.protobuf")
excludeGroup(it, "io.spine.tools")
}

/*
* Add the dependency onto `io.spine.tools:compiler-gradle-api`,
* so that CoreJvm Gradle Plugin can add it to a project.
*/
val compilerGradleApi = Node(dependencies, "dependency")
compilerGradleApi.let {
Node(it, "groupId", "io.spine.tools")
Node(it, "artifactId", "compiler-gradle-api")
Node(it, "version", Compiler.version)
Node(it, "scope", "runtime")
}
Node(compilerGradleApi, "exclusions").let {
excludeGroup(it, "org.jetbrains.kotlin")
excludeGroup(it, "com.google.protobuf")
excludeGroup(it, "io.spine.tools")
}

/*
* Add the dependency onto `io.spine.tools:compiler-params`,
* so that it is available in the classpath.
*/
val compilerParams = Node(dependencies, "dependency")
compilerParams.let {
Node(it, "groupId", "io.spine.tools")
Node(it, "artifactId", "compiler-params")
Node(it, "version", Compiler.version)
Node(it, "scope", "runtime")
}
Node(compilerParams, "exclusions").let {
excludeGroup(it, "org.jetbrains.kotlin")
excludeGroup(it, "com.google.protobuf")
excludeGroup(it, "io.spine.tools")
}

/*
* Add the dependency on Protobuf Gradle Plugin so that we can add it
* from our code. The code in `pom.xml` would look like this:
Expand All @@ -224,7 +275,7 @@ publishing {
}

/*
* Add the dependency on Protobuf Java library so that we can add it
* Add the dependency on the Protobuf Java library so that we can add it
* from our code. The code in `pom.xml` would look like this:
* ```
* <dependency>
Expand All @@ -242,6 +293,25 @@ publishing {
Node(it, "scope", "runtime")
}

/*
* Add the dependency on the Protobuf Java Util library so that we can add it
* from our code. The code in `pom.xml` would look like this:
* ```
* <dependency>
* <groupId>com.google.protobuf</groupId>
* <artifactId>protobuf-java-util</artifactId>
* <version>${Protobuf.version}</version>
* <scope>runtime</scope>
* </dependency>
* ```
*/
Node(dependencies, "dependency").let {
Node(it, "groupId", "com.google.protobuf")
Node(it, "artifactId", "protobuf-java-util")
Node(it, "version", Protobuf.version)
Node(it, "scope", "runtime")
}

/*
* Add the dependency on Protobuf Kotlin library so that we can add it
* from our code. The code in `pom.xml` would look like this:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine.tools</groupId>
<artifactId>core-jvm-compiler</artifactId>
<version>2.0.0-SNAPSHOT.051</version>
<version>2.0.0-SNAPSHOT.052</version>

<inceptionYear>2015</inceptionYear>

Expand Down
2 changes: 0 additions & 2 deletions tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ buildscript {
classpath(io.spine.dependency.build.ErrorProne.GradlePlugin.lib) {
exclude(group = "com.google.guava")
}
classpath(compiler.pluginLib)
classpath(io.spine.dependency.local.Compiler.pluginLib)
classpath(io.spine.dependency.local.CoreJvmCompiler.pluginLibNew(coreJvmCompilerVersion))
classpath(enforcedPlatform(io.spine.dependency.kotlinx.Coroutines.bom))
classpath(enforcedPlatform(io.spine.dependency.lib.Grpc.bom))
Expand Down
2 changes: 1 addition & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
*
* Do not rename this property, as it is also used in the integration tests via its name.
*/
val coreJvmCompilerVersion by extra("2.0.0-SNAPSHOT.051")
val coreJvmCompilerVersion by extra("2.0.0-SNAPSHOT.052")
val versionToPublish by extra(coreJvmCompilerVersion)
Loading