Skip to content

Commit 72bef10

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Upgrade from [6-year-old](https://repo1.maven.org/maven2/com/google/protobuf/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
1 parent 1de7695 commit 72bef10

16 files changed

+2350
-12
lines changed

extensions/liteproto/pom.xml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
</dependency>
3939
<dependency>
4040
<groupId>com.google.protobuf</groupId>
41-
<artifactId>protobuf-lite</artifactId>
42-
<!-- protobuf-lite is not compatible with protobuf-java, so we mark it optional. -->
41+
<artifactId>protobuf-javalite</artifactId>
42+
<!-- protobuf-javalite is not compatible with protobuf-java, so we mark it optional. -->
4343
<optional>true</optional>
4444
</dependency>
4545
</dependencies>
@@ -60,11 +60,13 @@
6060
<groupId>org.xolstice.maven.plugins</groupId>
6161
<artifactId>protobuf-maven-plugin</artifactId>
6262
<configuration>
63-
<protocArtifact>com.google.protobuf:protoc:${protobuf-lite.protoc.version}:exe:${os.detected.classifier}</protocArtifact>
63+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
6464
<includes>
6565
<param>test_message_lite2.proto</param>
6666
<param>test_message_lite3.proto</param>
6767
</includes>
68+
<!-- 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. -->
69+
<skip>true</skip>
6870
</configuration>
6971
<executions>
7072
<execution>
@@ -73,6 +75,27 @@
7375
<goals>
7476
<goal>test-compile</goal>
7577
</goals>
78+
<configuration>
79+
<javaOptions>lite</javaOptions>
80+
</configuration>
81+
</execution>
82+
</executions>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.codehaus.mojo</groupId>
86+
<artifactId>build-helper-maven-plugin</artifactId>
87+
<executions>
88+
<execution>
89+
<id>copy-proto-generated-code</id>
90+
<phase>generate-test-sources</phase>
91+
<goals>
92+
<goal>add-test-source</goal>
93+
</goals>
94+
<configuration>
95+
<sources>
96+
<source>pre-generated-test-sources</source>
97+
</sources>
98+
</configuration>
7699
</execution>
77100
</executions>
78101
</plugin>

extensions/liteproto/pre-generated-test-sources/protobuf/java/com/google/common/truth/extensions/proto/OtherTestMessageLite2.java

Lines changed: 256 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/liteproto/pre-generated-test-sources/protobuf/java/com/google/common/truth/extensions/proto/OtherTestMessageLite2OrBuilder.java

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)