Skip to content

Commit

Permalink
Allow overriding protoc.version via the commandline with higher prece…
Browse files Browse the repository at this point in the history
…dence than <protocVersion>
  • Loading branch information
ascopes committed Jan 21, 2024
1 parent 16ccdaa commit 7ebea03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.isLiteEnabled(liteOnly)
.mavenSession(session)
.outputDirectory(actualOutputDirectory)
.protocVersion(protocVersion)
.protocVersion(protocVersion())
.sourceRootRegistrar(sourceRootRegistrar())
.build();

Expand Down Expand Up @@ -338,6 +338,16 @@ protected void validate() {
});
}

private String protocVersion() {
// Give precedence to overriding the protoc version via the command line
// in case the Maven binaries are incompatible with the current system.
var overriddenVersion = System.getProperty("protoc.version");
if (overriddenVersion != null) {
return overriddenVersion;
}
return protocVersion;
}

private Collection<Path> parsePaths(@Nullable Collection<String> paths) {
if (paths == null) {
return List.of();
Expand Down
7 changes: 7 additions & 0 deletions src/site/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ and will be output to `target/generated-sources/protobuf`
(or `target/generated-test-sources/protobuf` for tests). This can be overridden
in the `configuration` block if needed.

The `protoc` version itself can be set via the `<protocVersion>` configuration parameter
as shown above, or can be set via the `protoc.version` property in your POM. It may
optionally be totally overridden on the command line by passing `-Dprotoc.version=xxx`,
in which case the `<protocVersion>` and `protoc.version` will be ignored. This is done
to allow users who may have an incompatible system to be able to request a build using
the `$PATH`-based `protoc` binary on their system (documented later in this page).

## Dependencies

It is worth noting that you will need to include the `protobuf-java` dependency
Expand Down

0 comments on commit 7ebea03

Please sign in to comment.