Skip to content

Commit ee09347

Browse files
Merge pull request #70 from SpineEventEngine/fix-dependency-on-compiler-gradle-api
Fix dependencies of the `plugin-bundle` module
2 parents db66dde + e68c196 commit ee09347

File tree

8 files changed

+126
-51
lines changed

8 files changed

+126
-51
lines changed

dependencies.md

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

gradle-plugins/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ artifactMeta {
6161
}
6262

6363
dependencies {
64+
compileOnly(gradleKotlinDsl())
6465
implementation(Compiler.pluginLib)
6566
implementation(Compiler.params)
6667
implementation(ToolBase.jvmTools)

gradle-plugins/src/main/kotlin/io/spine/tools/core/jvm/gradle/plugins/CompilerConfigPlugin.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
package io.spine.tools.core.jvm.gradle.plugins
3030

3131
import io.spine.tools.compiler.gradle.api.CompilerSettings
32-
import io.spine.tools.compiler.gradle.api.Names.GRADLE_PLUGIN_ID
3332
import io.spine.tools.compiler.gradle.api.addUserClasspathDependency
3433
import io.spine.tools.compiler.gradle.api.compilerSettings
3534
import io.spine.tools.compiler.gradle.api.compilerWorkingDir
@@ -59,6 +58,8 @@ import org.gradle.api.provider.Provider
5958
import org.gradle.kotlin.dsl.register
6059
import org.gradle.kotlin.dsl.withType
6160
import io.spine.tools.compiler.plugin.Plugin as CompilerPlugin
61+
import io.spine.tools.compiler.gradle.plugin.Plugin as CompilerGradlePlugin
62+
import org.gradle.kotlin.dsl.apply
6263

6364
/**
6465
* The plugin that configures the Spine Compiler for the associated project.
@@ -86,7 +87,9 @@ internal class CompilerConfigPlugin : Plugin<Project> {
8687
project.afterEvaluate {
8788
it.configureCompiler()
8889
}
89-
project.pluginManager.apply(GRADLE_PLUGIN_ID)
90+
// Apply the Compiler Gradle Plugin so that we can manipulate the compiler settings.
91+
// We do not want the user to add it manually.
92+
project.apply<CompilerGradlePlugin>()
9093
}
9194

9295
companion object {

gradle-plugins/src/main/kotlin/io/spine/tools/core/jvm/gradle/plugins/CoreJvmPlugin.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

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

29+
import com.google.protobuf.gradle.ProtobufPlugin
2930
import io.spine.string.simply
3031
import io.spine.tools.core.jvm.VersionHolder
3132
import io.spine.tools.core.jvm.gradle.CoreJvmOptions
@@ -39,6 +40,7 @@ import io.spine.tools.gradle.DslSpec
3940
import io.spine.tools.gradle.lib.LibraryPlugin
4041
import org.gradle.api.Plugin
4142
import org.gradle.api.Project
43+
import org.gradle.kotlin.dsl.apply
4244

4345
/**
4446
* Spine Model Compiler for Java Gradle plugin.
@@ -76,8 +78,7 @@ public class CoreJvmPlugin : LibraryPlugin<CoreJvmOptions>(
7678
private fun Project.applyProtobufPlugin() {
7779
if (!pluginManager.hasPlugin(ProtobufGradlePlugin.id)) {
7880
// We carry the plugin as a runtime dependency of the fat JAR.
79-
// So it will be available in the build classpath and found by the ID.
80-
pluginManager.apply(ProtobufGradlePlugin.id)
81+
project.apply<ProtobufPlugin>()
8182
}
8283
}
8384

@@ -105,11 +106,11 @@ private fun Project.createAndApplyPlugins() {
105106
RoutingPlugin()
106107
)
107108
plugins.forEach {
108-
apply(it)
109+
doApply(it)
109110
}
110111
}
111112

112-
private fun Project.apply(plugin: Plugin<Project>) {
113+
private fun Project.doApply(plugin: Plugin<Project>) {
113114
logger.debug { "Applying `${plugin.javaClass.name}` plugin." }
114115
plugin.apply(project)
115116
}

plugin-bundle/build.gradle.kts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,57 @@ publishing {
204204
excludeGroup(it, "io.spine.tools")
205205
}
206206

207+
/*
208+
* Add the dependency onto `io.spine.tools:compiler-gradle-plugin`,
209+
* so that CoreJvm Gradle Plugin can add it to a project.
210+
*/
211+
val compilerGradlePlugin = Node(dependencies, "dependency")
212+
compilerGradlePlugin.let {
213+
Node(it, "groupId", "io.spine.tools")
214+
Node(it, "artifactId", "compiler-gradle-plugin")
215+
Node(it, "version", Compiler.version)
216+
Node(it, "scope", "runtime")
217+
}
218+
Node(compilerGradlePlugin, "exclusions").let {
219+
excludeGroup(it, "org.jetbrains.kotlin")
220+
excludeGroup(it, "com.google.protobuf")
221+
excludeGroup(it, "io.spine.tools")
222+
}
223+
224+
/*
225+
* Add the dependency onto `io.spine.tools:compiler-gradle-api`,
226+
* so that CoreJvm Gradle Plugin can add it to a project.
227+
*/
228+
val compilerGradleApi = Node(dependencies, "dependency")
229+
compilerGradleApi.let {
230+
Node(it, "groupId", "io.spine.tools")
231+
Node(it, "artifactId", "compiler-gradle-api")
232+
Node(it, "version", Compiler.version)
233+
Node(it, "scope", "runtime")
234+
}
235+
Node(compilerGradleApi, "exclusions").let {
236+
excludeGroup(it, "org.jetbrains.kotlin")
237+
excludeGroup(it, "com.google.protobuf")
238+
excludeGroup(it, "io.spine.tools")
239+
}
240+
241+
/*
242+
* Add the dependency onto `io.spine.tools:compiler-params`,
243+
* so that it is available in the classpath.
244+
*/
245+
val compilerParams = Node(dependencies, "dependency")
246+
compilerParams.let {
247+
Node(it, "groupId", "io.spine.tools")
248+
Node(it, "artifactId", "compiler-params")
249+
Node(it, "version", Compiler.version)
250+
Node(it, "scope", "runtime")
251+
}
252+
Node(compilerParams, "exclusions").let {
253+
excludeGroup(it, "org.jetbrains.kotlin")
254+
excludeGroup(it, "com.google.protobuf")
255+
excludeGroup(it, "io.spine.tools")
256+
}
257+
207258
/*
208259
* Add the dependency on Protobuf Gradle Plugin so that we can add it
209260
* from our code. The code in `pom.xml` would look like this:
@@ -224,7 +275,7 @@ publishing {
224275
}
225276

226277
/*
227-
* Add the dependency on Protobuf Java library so that we can add it
278+
* Add the dependency on the Protobuf Java library so that we can add it
228279
* from our code. The code in `pom.xml` would look like this:
229280
* ```
230281
* <dependency>
@@ -242,6 +293,27 @@ publishing {
242293
Node(it, "scope", "runtime")
243294
}
244295

296+
/*
297+
* Add the dependency on the Protobuf Java Util library because it is
298+
* used from the `compiler-params` module. Since we exclude the dependencies
299+
* on Protobuf, we need to add the Util library manually.
300+
* The code in `pom.xml` would look like this:
301+
* ```
302+
* <dependency>
303+
* <groupId>com.google.protobuf</groupId>
304+
* <artifactId>protobuf-java-util</artifactId>
305+
* <version>${Protobuf.version}</version>
306+
* <scope>runtime</scope>
307+
* </dependency>
308+
* ```
309+
*/
310+
Node(dependencies, "dependency").let {
311+
Node(it, "groupId", "com.google.protobuf")
312+
Node(it, "artifactId", "protobuf-java-util")
313+
Node(it, "version", Protobuf.version)
314+
Node(it, "scope", "runtime")
315+
}
316+
245317
/*
246318
* Add the dependency on Protobuf Kotlin library so that we can add it
247319
* from our code. The code in `pom.xml` would look like this:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
1010
-->
1111
<groupId>io.spine.tools</groupId>
1212
<artifactId>core-jvm-compiler</artifactId>
13-
<version>2.0.0-SNAPSHOT.051</version>
13+
<version>2.0.0-SNAPSHOT.052</version>
1414

1515
<inceptionYear>2015</inceptionYear>
1616

tests/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ buildscript {
6565
classpath(io.spine.dependency.build.ErrorProne.GradlePlugin.lib) {
6666
exclude(group = "com.google.guava")
6767
}
68-
classpath(compiler.pluginLib)
69-
classpath(io.spine.dependency.local.Compiler.pluginLib)
7068
classpath(io.spine.dependency.local.CoreJvmCompiler.pluginLibNew(coreJvmCompilerVersion))
7169
classpath(enforcedPlatform(io.spine.dependency.kotlinx.Coroutines.bom))
7270
classpath(enforcedPlatform(io.spine.dependency.lib.Grpc.bom))

version.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
*
3030
* Do not rename this property, as it is also used in the integration tests via its name.
3131
*/
32-
val coreJvmCompilerVersion by extra("2.0.0-SNAPSHOT.051")
32+
val coreJvmCompilerVersion by extra("2.0.0-SNAPSHOT.052")
3333
val versionToPublish by extra(coreJvmCompilerVersion)

0 commit comments

Comments
 (0)