From 7ebea035f3d7f616d42f520f822120133edec539 Mon Sep 17 00:00:00 2001 From: ascopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 21 Jan 2024 09:56:15 +0000 Subject: [PATCH] Allow overriding protoc.version via the commandline with higher precedence than --- .../protobufmavenplugin/AbstractGenerateMojo.java | 12 +++++++++++- src/site/markdown/index.md | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java b/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java index fa034ca3..b049c98f 100644 --- a/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java +++ b/src/main/java/io/github/ascopes/protobufmavenplugin/AbstractGenerateMojo.java @@ -250,7 +250,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { .isLiteEnabled(liteOnly) .mavenSession(session) .outputDirectory(actualOutputDirectory) - .protocVersion(protocVersion) + .protocVersion(protocVersion()) .sourceRootRegistrar(sourceRootRegistrar()) .build(); @@ -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 parsePaths(@Nullable Collection paths) { if (paths == null) { return List.of(); diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index c5a809d2..e1424ba2 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -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 `` 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 `` 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