Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rotobuf/protobuf-lite/3.0.1/) `protobuf-lite` to its modern equivalent, `protobuf-javalite`.

This change should mostly not be user-visible, since we [declare this dependency as `optional`](https://github.com/google/truth/blob/1de76958abc8f3dbfad07d142bd290dc53d7427a/extensions/liteproto/pom.xml#L43).

The new version doesn't support the `optimize_for = LITE_RUNTIME` option in `.proto` files, presumably on the theory that you should be able to compile the same protobuf for both the "lite" and "speed" runtimes. Unfortunately, xolstice/protobuf-maven-plugin does not provide a way to pass the `lite` option to the protobuf compiler. (That option was added in xolstice/protobuf-maven-plugin@3ae165e, but that is not yet part of [a release](https://github.com/xolstice/protobuf-maven-plugin/tags). And the project doesn't appear very active lately.)

So we can't generate the Java protobuf classes with that plugin. Maybe there's another plugin we could use, if only one that runs an arbitrary executable? But for now, I'm taking another approach: I'm submitting the generated sources.

To generate them, I ran `mvn clean install -X -e`, found the location of the protobuf executable and arguments in the output, and ran it with `--java_out=lite:/the/path/from/the/output`. Then I tweaked the Maven setup to build those sources instead of generating and building the protobuf ones.

Yuck. This could cause someone some frustration down the line when it comes time to make a change to the test protos. But given that we haven't had to change those protos yet in their 6+ years of existence, I'm hoping for the best.

Another alternative for us to consider is to just not run these specific tests in our open-source build.

RELNOTES=n/a
PiperOrigin-RevId: 486951466
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Nov 15, 2022
1 parent 1de7695 commit fd53ec5
Show file tree
Hide file tree
Showing 17 changed files with 2,579 additions and 12 deletions.
29 changes: 26 additions & 3 deletions extensions/liteproto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-lite</artifactId>
<!-- protobuf-lite is not compatible with protobuf-java, so we mark it optional. -->
<artifactId>protobuf-javalite</artifactId>
<!-- protobuf-javalite is not compatible with protobuf-java, so we mark it optional. -->
<optional>true</optional>
</dependency>
</dependencies>
Expand All @@ -60,11 +60,13 @@
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf-lite.protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<includes>
<param>test_message_lite2.proto</param>
<param>test_message_lite3.proto</param>
</includes>
<!-- TODO(cpovirk): After https://github.com/xolstice/protobuf-maven-plugin/commit/3ae165e5f6b33f8a6221ece11cc79a7df5eeb8df is in a release (so that javaOptions works below), restore this compilation step, remove the copy-proto-generated-code step below, and delete the pre-generated-test-sources directory. Then *hopefully* this will Just Work. -->
<skip>true</skip>
</configuration>
<executions>
<execution>
Expand All @@ -73,6 +75,27 @@
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<javaOptions>lite</javaOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>copy-proto-generated-code</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>pre-generated-test-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd53ec5

Please sign in to comment.