Skip to content

Commit

Permalink
Use relocated protobuf runtime
Browse files Browse the repository at this point in the history
Generated protobuf code must be run with the protobuf runtime using the exact same version as the generator used. This is currently a soft constraint, but it is likely that protobuf will enforce that in future protobuf versions. Using a different version of the protobuf runtime can (and does) lead to issues at runtime, see [this issue for an example](protocolbuffers/protobuf#11986).

This change adds a new Nessie artifact `nessie-protobuf-relocated` which contains a relocated protobuf runtime that is used by all other Nessie artifacts.

Also:
* Move `*.proto` files into the directories corresponding to the Java package names.
* Remove the `ProtobufHelperPlugin`, as the underlying issue (not exposing the generated java source folders in IDEs) has been fixed.
* Do not apply checkstyle to Gradle projects that just generate protobuf code (the `ProtobufHelperPlugin` did that before).

Side note: CEL-Java heavily depends on protobuf itself via its API and not just as a runtime/compile-only dependency. As long as no generated protobuf code is being used, it _should_ be okay to use a different protobuf version at runtime, but there is and will be no guarantee.
  • Loading branch information
snazy committed Mar 23, 2023
1 parent 3830124 commit 8d0a843
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 56 deletions.
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies {
implementation(baselibs.jandex)
implementation(baselibs.idea.ext)
implementation(baselibs.shadow)
implementation(baselibs.protobuf)
implementation(baselibs.errorprone)
implementation(baselibs.nessie.buildsupport.reflectionconfig)

Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/Checkstyle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import org.gradle.kotlin.dsl.withType
class NessieCheckstylePlugin : Plugin<Project> {
override fun apply(project: Project): Unit =
project.run {
if (project.name.endsWith("-proto")) {
return
}

apply<CheckstylePlugin>()
configure<CheckstyleExtension> {
toolVersion = libsRequiredVersion("checkstyle")
Expand Down
53 changes: 0 additions & 53 deletions buildSrc/src/main/kotlin/ProtobufHelperPlugin.kt

This file was deleted.

2 changes: 0 additions & 2 deletions gradle/baselibs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ errorpronePlugin = "3.0.1"
jandexPlugin = "1.87"
junit = "5.9.2"
nessieBuildPlugins = "0.2.21"
protobufPlugin = "0.9.2"
shadowPlugin = "8.1.1"
spotlessPlugin = "6.17.0"

Expand All @@ -21,4 +20,3 @@ junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params" }
nessie-buildsupport-reflectionconfig = { module = "org.projectnessie.buildsupport:reflection-config", version.ref = "nessieBuildPlugins" }
shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadowPlugin" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotlessPlugin" }
protobuf = { module = "com.google.protobuf:protobuf-gradle-plugin", version.ref = "protobufPlugin" }
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,5 @@ jmh = { id = "me.champeau.jmh", version = "0.7.0" }
nessie-run = { id = "org.projectnessie", version = "0.29.0" }
nexus-publish-plugin = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" }
node-gradle = { id = "com.github.node-gradle.node", version = "3.5.1" }
protobuf = { id = "com.google.protobuf", version = "0.9.2" }
quarkus = { id = "io.quarkus", version.ref = "quarkus" }
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nessie-services=servers/services
nessie-server-store=servers/store
nessie-server-store-proto=servers/store-proto
nessie-content-generator=tools/content-generator
nessie-protobuf-relocated=tools/protobuf-relocated
nessie-ui=ui
nessie-versioned-persist-adapter=versioned/persist/adapter
nessie-versioned-persist-bench=versioned/persist/bench
Expand Down
53 changes: 53 additions & 0 deletions tools/protobuf-relocated/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2023 Dremio
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
`java-library`
`maven-publish`
signing
id("org.projectnessie.buildsupport.reflectionconfig")
`nessie-conventions`
}

apply<NessieShadowJarPlugin>()

extra["maven.name"] = "Nessie - Relocated Protobuf ${libs.protobuf.java.get().version}"

dependencies { implementation(libs.protobuf.java) }

reflectionConfig {
// Consider classes that extend one of these classes...
classExtendsPatterns.set(
listOf(
"com.google.protobuf.GeneratedMessageV3",
"com.google.protobuf.GeneratedMessageV3.Builder"
)
)
// ... and classes the implement this interface.
classImplementsPatterns.set(listOf("com.google.protobuf.ProtocolMessageEnum"))
// Also include generated classes (e.g. google.protobuf.Empty) via the "runtimeClasspath",
// which contains the the "com.google.protobuf:protobuf-java" dependency.
includeConfigurations.set(listOf("runtimeClasspath"))
relocations.put("com[.]google[.]protobuf[.]", "org.projectnessie.nessie.relocated.protobuf.$1")
}

tasks.named<ShadowJar>("shadowJar") {
dependsOn("generateReflectionConfig")
relocate("com.google.protobuf", "org.projectnessie.nessie.relocated.protobuf")
manifest { attributes["Google-Protobuf-Version"] = libs.protobuf.java.get().version }
}

0 comments on commit 8d0a843

Please sign in to comment.