Skip to content

Commit 0337441

Browse files
Merge pull request #53 from SpineEventEngine/exclude-protobuf-from-fat-jar
Exclude Protobuf from fat JAR
2 parents cc87e8f + 07b9c30 commit 0337441

File tree

14 files changed

+218
-131
lines changed

14 files changed

+218
-131
lines changed

annotation/src/test/resources/annotator-plugin-test/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ buildscript {
4646
classpath(io.spine.dependency.lib.Protobuf.GradlePlugin.lib) {
4747
exclude(group = "com.google.guava")
4848
}
49+
classpath(io.spine.dependency.local.Compiler.pluginLib)
4950
classpath(io.spine.dependency.local.CoreJvmCompiler.pluginLibNew(coreJvmCompilerVersion))
5051
}
5152
}

base/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ val moduleArtifactId = "core-jvm-base"
4646
artifactMeta {
4747
artifactId.set(moduleArtifactId)
4848
addDependencies(
49+
Compiler.pluginLib,
4950
CoreJvm.server,
5051
CoreJvm.client,
5152
)

base/src/main/kotlin/io/spine/tools/core/jvm/gradle/Meta.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import io.spine.tools.meta.Module
3737
*/
3838
internal object Meta : LazyMeta(Module(SPINE_TOOLS_GROUP, "core-jvm-base"))
3939

40+
/**
41+
* Dependencies on the CoreJvm Library.
42+
*/
4043
internal object CoreJvm {
4144

4245
/**
@@ -56,3 +59,15 @@ internal object CoreJvm {
5659
*/
5760
internal val client = dependency("spine-client")
5861
}
62+
63+
/**
64+
* Dependencies on Spine Compiler.
65+
*/
66+
public object Compiler {
67+
68+
/**
69+
* The dependency on the Compiler's Gradle plugin.
70+
*/
71+
public val pluginLib: LazyDependency =
72+
LazyDependency(Meta, Module(SPINE_TOOLS_GROUP, "compiler-gradle-plugin"))
73+
}

dependencies.md

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

gradle-plugins/src/main/resources/plugin_runner.bat

Lines changed: 0 additions & 3 deletions
This file was deleted.

gradle-plugins/src/main/resources/plugin_runner.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

plugin-bundle/build.gradle.kts

Lines changed: 134 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
import groovy.util.Node
28+
import groovy.util.NodeList
2829
import io.spine.dependency.build.Ksp
2930
import io.spine.dependency.lib.Protobuf
3031
import io.spine.dependency.local.Compiler
@@ -145,15 +146,61 @@ publishing {
145146
* </dependency>
146147
* ```
147148
*/
148-
val dependency = Node(dependencies, "dependency")
149-
dependency.let {
149+
val compilerApi = Node(dependencies, "dependency")
150+
compilerApi.let {
150151
Node(it, "groupId", "io.spine.tools")
151152
Node(it, "artifactId", "compiler-api")
152153
Node(it, "version", Compiler.version)
153154
Node(it, "scope", "runtime")
154155
}
155156

156-
Node(dependency, "exclusions").let {
157+
Node(compilerApi, "exclusions").let {
158+
excludeGroup(it, "org.jetbrains.kotlin")
159+
excludeGroup(it, "com.google.protobuf")
160+
excludeGroup(it, "io.spine.tools")
161+
}
162+
163+
/*
164+
* Add the dependency onto `io.spine.tools:compiler-jvm`,
165+
* due to the same reasons as stated above.
166+
*
167+
* This dependency is required, in particular, to access
168+
* the Proto definitions used by CoreJvm Gradle plugin extension
169+
* via `CoreJvmOptions`.
170+
*
171+
* The appended code in `pom.xml` would look like this:
172+
* ```
173+
* <dependency>
174+
* <groupId>io.spine.tools</groupId>
175+
* <artifactId>compiler-jvm</artifactId>
176+
* <version>${Compiler.version}</version>
177+
* <scope>runtime</scope>
178+
* <exclusions>
179+
* <exclusion>
180+
* <groupId>org.jetbrains.kotlin</groupId>
181+
* <artifactId>*</artifactId>
182+
* </exclusion>
183+
* <exclusion>
184+
* <groupId>com.google.protobuf</groupId>
185+
* <artifactId>*</artifactId>
186+
* </exclusion>
187+
* <exclusion>
188+
* <groupId>io.spine.tools</groupId>
189+
* <artifactId>*</artifactId>
190+
* </exclusion>
191+
* </exclusions>
192+
* </dependency>
193+
* ```
194+
*/
195+
val compilerJvm = Node(dependencies, "dependency")
196+
compilerJvm.let {
197+
Node(it, "groupId", "io.spine.tools")
198+
Node(it, "artifactId", "compiler-jvm")
199+
Node(it, "version", Compiler.version)
200+
Node(it, "scope", "runtime")
201+
}
202+
203+
Node(compilerJvm, "exclusions").let {
157204
excludeGroup(it, "org.jetbrains.kotlin")
158205
excludeGroup(it, "com.google.protobuf")
159206
excludeGroup(it, "io.spine.tools")
@@ -177,6 +224,45 @@ publishing {
177224
Node(it, "version", Protobuf.GradlePlugin.version)
178225
Node(it, "scope", "runtime")
179226
}
227+
228+
/*
229+
* Add the dependency on Protobuf Java library so that we can add it
230+
* from our code. The code in `pom.xml` would look like this:
231+
* ```
232+
* <dependency>
233+
* <groupId>com.google.protobuf</groupId>
234+
* <artifactId>protobuf-java</artifactId>
235+
* <version>${Protobuf.version}</version>
236+
* <scope>runtime</scope>
237+
* </dependency>
238+
* ```
239+
*/
240+
Node(dependencies, "dependency").let {
241+
Node(it, "groupId", "com.google.protobuf")
242+
Node(it, "artifactId", "protobuf-java")
243+
Node(it, "version", Protobuf.version)
244+
Node(it, "scope", "runtime")
245+
}
246+
247+
/*
248+
* Add the dependency on Protobuf Kotlin library so that we can add it
249+
* from our code. The code in `pom.xml` would look like this:
250+
* ```
251+
* <dependency>
252+
* <groupId>com.google.protobuf</groupId>
253+
* <artifactId>protobuf-kotlin</artifactId>
254+
* <version>${Protobuf.version}</version>
255+
* <scope>runtime</scope>
256+
* </dependency>
257+
* ```
258+
*/
259+
Node(dependencies, "dependency").let {
260+
Node(it, "groupId", "com.google.protobuf")
261+
Node(it, "artifactId", "protobuf-kotlin")
262+
Node(it, "version", Protobuf.version)
263+
Node(it, "scope", "runtime")
264+
}
265+
180266
/*
181267
* Add the dependency on KSP Gradle Plugin as well.
182268
* The expected XML output:
@@ -257,52 +343,22 @@ tasks.shadowJar {
257343
"kotlinx/coroutines/**",
258344

259345
/*
260-
* The Protobuf Gradle Plugin will be available in the classpath because
346+
* Protobuf runtime and Gradle plugin will be available in the classpath because
261347
* fat JAR has the Maven `runtime` dependency on it.
262-
* Please see manipulations with `pom.xml` below.
348+
* Please see manipulations with `pom.xml` in the `publishing` block above.
263349
*/
264-
"com/google/protobuf/gradle/**",
350+
"com/google/protobuf/**",
265351
"META-INF/gradle-plugins/com.google.protobuf.properties",
266352

267353
/*
268354
* Excluding these types to avoid clashes at user's build classpath.
269355
*
270-
* The ProtoData plugin will be added to the user's build via a dependency.
356+
* The Compiler Gradle plugin will be added to the user's build via a dependency.
271357
* See the `pom.xml` manipulations above.
272358
*/
273-
"io/spine/protodata/*",
274-
"io/spine/protodata/plugin/**",
275-
"io/spine/protodata/renderer/**",
276-
"io/spine/protodata/type/**",
277-
"io/spine/protodata/cli/app/**",
278-
"io/spine/protodata/gradle/plugin/**",
279-
"io/spine/protodata/java/*",
280-
"io/spine/protodata/java/annotation/**",
281-
"io/spine/protodata/java/file/**",
282-
"io/spine/protodata/protoc/**",
283-
284-
// TODO: Uncomment these after the Spine Compiler is available from Gradle Plugin Portal.
285-
//
286-
// "io/spine/tools/compiler/*",
287-
// "io/spine/tools/compiler/plugin/**",
288-
// "io/spine/tools/compiler/renderer/**",
289-
// "io/spine/tools/compiler/type/**",
290-
// "io/spine/tools/compiler/cli/app/**",
291-
// "io/spine/tools/compiler/gradle/plugin/**",
292-
// "io/spine/tools/compiler/jvm/*",
293-
// "io/spine/tools/compiler/jvm/annotation/**",
294-
// "io/spine/tools/compiler/jvm/file/**",
295-
// "io/spine/tools/compiler/protoc/**",
296-
// "spine/compiler/**",
297-
298-
// TODO: Uncomment these as well once the Spine Compiler is ready.
299-
// Plugin declaration
300-
"META-INF/gradle-plugins/io.spine.protodata.properties",
301-
// "META-INF/gradle-plugins/io.spine.compiler.properties",
302-
303-
304-
// Protobuf definitions
305-
"spine/protodata/**",
359+
"io/spine/tools/compiler/**",
360+
"spine/compiler/**", // Protobuf definitions
361+
"META-INF/gradle-plugins/io.spine.compiler.properties", // Plugin declaration
306362

307363
/**
308364
* Exclude Gradle types to reduce the size of the resulting JAR.
@@ -399,3 +455,41 @@ gradlePlugin {
399455
}
400456
}
401457
}
458+
459+
/**
460+
* Make the `PluginMarkerMaven` publication refer to the fat JAR produced
461+
* the `plugin-bundle` module.
462+
*
463+
* The publication will still refer to the `plubin-bundle` artifact which
464+
* should be probably removed eventually.
465+
*/
466+
afterEvaluate {
467+
publishing {
468+
publications.withType<MavenPublication>().configureEach {
469+
if (name.endsWith("PluginMarkerMaven")) {
470+
pom.withXml {
471+
val dependencies = dependenciesNode()
472+
val dependency = Node(dependencies, "dependency")
473+
dependency.let {
474+
Node(it, "groupId", "io.spine.tools")
475+
Node(it, "artifactId", "core-jvm-plugins")
476+
Node(it, "version", project.version)
477+
Node(it, "scope", "runtime")
478+
}
479+
}
480+
}
481+
}
482+
}
483+
}
484+
485+
/**
486+
* Finds or creates the `dependencies` node at the project node.
487+
*/
488+
private fun XmlProvider.dependenciesNode(): Node {
489+
val nodeName = "dependencies"
490+
val projectNode = asNode()
491+
val dependencies = (projectNode.get(nodeName) as? NodeList)
492+
?.firstOrNull() as? Node
493+
?: projectNode.appendNode(nodeName)
494+
return dependencies
495+
}

plugin-bundle/src/test/kotlin/io/spine/tools/core/jvm/gradle/plugins/CoreJvmPluginIgTest.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package io.spine.tools.core.jvm.gradle.plugins
2828

2929
import io.kotest.matchers.shouldBe
30+
import io.spine.tools.core.jvm.gradle.Compiler
3031
import io.spine.tools.core.jvm.gradle.module.ArtifactRegistry
3132
import io.spine.tools.gradle.task.BaseTaskName
3233
import io.spine.tools.gradle.task.TaskName
@@ -43,29 +44,31 @@ import org.junit.jupiter.api.io.TempDir
4344
class CoreJvmPluginIgTest {
4445

4546
companion object {
47+
val repos = """
48+
|repositories {
49+
| mavenLocal()
50+
| maven { url = uri("${ArtifactRegistry.releases}") }
51+
| maven { url = uri("${ArtifactRegistry.snapshots}") }
52+
| mavenCentral()
53+
|}""".trimMargin()
54+
4655
@Language("kotlin")
47-
private val buildscriptWithClasspathDependency = """
56+
private val buildscriptWithFullClasspath = """
4857
|buildscript {
49-
| repositories {
50-
| mavenLocal()
51-
| maven { url = uri("${ArtifactRegistry.releases}") }
52-
| maven { url = uri("${ArtifactRegistry.snapshots}") }
53-
| mavenCentral()
54-
| }
58+
| $repos
5559
| dependencies {
5660
| classpath("io.spine.tools:core-jvm-plugins:${Meta.artifact.version}")
61+
| classpath("${Compiler.pluginLib.artifact.coordinates}")
5762
| }
5863
|}
5964
|""".trimMargin()
6065

6166
@Language("kotlin")
62-
private val buildscript = """
67+
private val buildscriptWithShortClasspath = """
6368
|buildscript {
64-
| repositories {
65-
| mavenLocal()
66-
| maven { url = uri("${ArtifactRegistry.releases}") }
67-
| maven { url = uri("${ArtifactRegistry.snapshots}") }
68-
| mavenCentral()
69+
| $repos
70+
| dependencies {
71+
| classpath("${Compiler.pluginLib.artifact.coordinates}")
6972
| }
7073
|}
7174
|""".trimMargin()
@@ -91,7 +94,7 @@ class CoreJvmPluginIgTest {
9194
@Test
9295
fun `apply to a single-module project via classpath`(@TempDir projectDir: File) {
9396
@Language("kotlin")
94-
val buildFile = buildscriptWithClasspathDependency + """
97+
val buildFile = buildscriptWithFullClasspath + """
9598
|plugins {
9699
| java
97100
| kotlin("jvm").version("${KotlinGradlePlugin.version}")
@@ -124,7 +127,7 @@ class CoreJvmPluginIgTest {
124127
@TempDir projectDir: File
125128
) {
126129
@Language("kotlin")
127-
val buildFile = buildscriptWithClasspathDependency + """
130+
val buildFile = buildscriptWithFullClasspath + """
128131
|plugins {
129132
| java
130133
| kotlin("jvm").version("${KotlinGradlePlugin.version}")
@@ -154,7 +157,7 @@ class CoreJvmPluginIgTest {
154157
@Test
155158
fun `be available via its ID and version`(@TempDir projectDir: File) {
156159
@Language("kotlin")
157-
val buildFile = buildscript + """
160+
val buildFile = buildscriptWithShortClasspath + """
158161
|plugins {
159162
| java
160163
| kotlin("jvm").version("${KotlinGradlePlugin.version}")

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.024</version>
13+
<version>2.0.0-SNAPSHOT.025</version>
1414

1515
<inceptionYear>2015</inceptionYear>
1616

0 commit comments

Comments
 (0)