-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use relocated protobuf runtime #6355
Conversation
Review notes: The PR contains multiple commits:
|
Another note: Quarkus itself (or better: some extensions) also pull in protobuf in the exact same version that Quarkus requires via the |
The "build tools integrations tests" failed for the "external Gradle build" - fix in the last new commit |
The "build tools integrations test" failed for PR projectnessie#6355 for the "external Gradle build". Reason is that the relocated protobuf jar is published via the Shadow plugin. `PublishingHelperPlugin` used the recommended approach to call `ShadowExtension.component(MavenPublication)`, which is fine for Maven poms, but is not enough for Gradle module metadata (the `.module` files published along the `.pom` files). The published Gradle module metadata files reference the "original" jar (named `*-raw.jar` in the Nessie build) in the included `apiElements` and `runtimeElements` variants, but that's wrong for Nessie and inconsistent with the published pom, because we want to _replace_ the "original" jar with the one produced by `ShadowJar`. Relevant pieces that assemble the Gradle component to be published are taken from Gradle's `Java(Base)Plugin` and `ShadowExtension`. The issue can be inspected in the published `.module` file (or one generated via the `generateMetadataFileForMavenPublication`, e.g. from `:nessie-spark-extensions-3.1_2.12`) project. Before this change, the file `build/publications/maven/module.json` contains these variants (simplified for readability): ``` { ... "variants": [ { "name": "apiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "external", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT-raw.jar", ... } ] }, ... (similar for runtimeElements) ... (javadoc + sources follow) { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] } ] } ``` With this change it looks as follows, note that the the duplicated `java-runtime` usage is gone and a `java-api` for the the shadowed bundling is present. This way, "external" builds can properly select the required variant. ``` { ... "variants": [ { "name": "shadowApiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, ... (javadoc + sources follow) ] } ```
The "build tools integrations test" failed for PR projectnessie#6355 for the "external Gradle build". Reason is that the relocated protobuf jar is published via the Shadow plugin. `PublishingHelperPlugin` used the recommended approach to call `ShadowExtension.component(MavenPublication)`, which is fine for Maven poms, but is not enough for Gradle module metadata (the `.module` files published along the `.pom` files). The published Gradle module metadata files reference the "original" jar (named `*-raw.jar` in the Nessie build) in the included `apiElements` and `runtimeElements` variants, but that's wrong for Nessie and inconsistent with the published pom, because we want to _replace_ the "original" jar with the one produced by `ShadowJar`. Relevant pieces that assemble the Gradle component to be published are taken from Gradle's `Java(Base)Plugin` and `ShadowExtension`. The issue can be inspected in the published `.module` file (or one generated via the `generateMetadataFileForMavenPublication`, e.g. from `:nessie-spark-extensions-3.1_2.12`) project. Before this change, the file `build/publications/maven/module.json` contains these variants (simplified for readability): ``` { ... "variants": [ { "name": "apiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "external", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT-raw.jar", ... } ] }, ... (similar for runtimeElements) ... (javadoc + sources follow) { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] } ] } ``` With this change it looks as follows, note that the the duplicated `java-runtime` usage is gone and a `java-api` for the the shadowed bundling is present. This way, "external" builds can properly select the required variant. ``` { ... "variants": [ { "name": "shadowApiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, ... (javadoc + sources follow) ] } ```
20f1a26
to
edd0fbe
Compare
Ugh - turned out that the published Gradle module metadata produced via the recommended way is broken. Created #6361 to fix it. |
dependencies { include(dependency(libs.protobuf.java.get())) } | ||
} | ||
|
||
tasks.named("compileJava") { finalizedBy(shadowJar) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this and the following are sadly necessary :(
@@ -185,6 +196,7 @@ class PublishingHelperPlugin : Plugin<Project> { | |||
// enforcedPlatform() dependency - but Quarkus requires enforcedPlatform(), so we have to | |||
// allow it. | |||
tasks.withType<GenerateModuleMetadata>().configureEach { | |||
val t = this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: leftover?
The "build tools integrations test" failed for PR projectnessie#6355 for the "external Gradle build". Reason is that the relocated protobuf jar is published via the Shadow plugin. `PublishingHelperPlugin` used the recommended approach to call `ShadowExtension.component(MavenPublication)`, which is fine for Maven poms, but is not enough for Gradle module metadata (the `.module` files published along the `.pom` files). The published Gradle module metadata files reference the "original" jar (named `*-raw.jar` in the Nessie build) in the included `apiElements` and `runtimeElements` variants, but that's wrong for Nessie and inconsistent with the published pom, because we want to _replace_ the "original" jar with the one produced by `ShadowJar`. Relevant pieces that assemble the Gradle component to be published are taken from Gradle's `Java(Base)Plugin` and `ShadowExtension`. The issue can be inspected in the published `.module` file (or one generated via the `generateMetadataFileForMavenPublication`, e.g. from `:nessie-spark-extensions-3.1_2.12`) project. Before this change, the file `build/publications/maven/module.json` contains these variants (simplified for readability): ``` { ... "variants": [ { "name": "apiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "external", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT-raw.jar", ... } ] }, ... (similar for runtimeElements) ... (javadoc + sources follow) { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] } ] } ``` With this change it looks as follows, note that the the duplicated `java-runtime` usage is gone and a `java-api` for the the shadowed bundling is present. This way, "external" builds can properly select the required variant. ``` { ... "variants": [ { "name": "shadowApiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, ... (javadoc + sources follow) ] } ```
The "build tools integrations test" failed for PR #6355 for the "external Gradle build". Reason is that the relocated protobuf jar is published via the Shadow plugin. `PublishingHelperPlugin` used the recommended approach to call `ShadowExtension.component(MavenPublication)`, which is fine for Maven poms, but is not enough for Gradle module metadata (the `.module` files published along the `.pom` files). The published Gradle module metadata files reference the "original" jar (named `*-raw.jar` in the Nessie build) in the included `apiElements` and `runtimeElements` variants, but that's wrong for Nessie and inconsistent with the published pom, because we want to _replace_ the "original" jar with the one produced by `ShadowJar`. Relevant pieces that assemble the Gradle component to be published are taken from Gradle's `Java(Base)Plugin` and `ShadowExtension`. The issue can be inspected in the published `.module` file (or one generated via the `generateMetadataFileForMavenPublication`, e.g. from `:nessie-spark-extensions-3.1_2.12`) project. Before this change, the file `build/publications/maven/module.json` contains these variants (simplified for readability): ``` { ... "variants": [ { "name": "apiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "external", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT-raw.jar", ... } ] }, ... (similar for runtimeElements) ... (javadoc + sources follow) { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] } ] } ``` With this change it looks as follows, note that the the duplicated `java-runtime` usage is gone and a `java-api` for the the shadowed bundling is present. This way, "external" builds can properly select the required variant. ``` { ... "variants": [ { "name": "shadowApiElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.jvm.version": 8, "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-api" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, { "name": "shadowRuntimeElements", "attributes": { "org.gradle.category": "library", "org.gradle.dependency.bundling": "shadowed", "org.gradle.libraryelements": "jar", "org.gradle.usage": "java-runtime" }, "files": [ { "name": "nessie-protobuf-relocated-0.52.4-SNAPSHOT.jar", ... } ] }, ... (javadoc + sources follow) ] } ```
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.
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.
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:
*.proto
files into the directories corresponding to the Java package names.ProtobufHelperPlugin
, as the underlying issue (not exposing the generated java source folders in IDEs) has been fixed.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.