diff --git a/dubbo-maven-plugin/pom.xml b/dubbo-maven-plugin/pom.xml
index 254e9f0324..24dec2d1ac 100644
--- a/dubbo-maven-plugin/pom.xml
+++ b/dubbo-maven-plugin/pom.xml
@@ -27,6 +27,11 @@
maven-plugin
Dubbo Maven Plugin
+
+ ${revision}
+ 3.25.0
+
+
org.apache.maven
@@ -66,6 +71,15 @@
2.11.0
+
+
+ com.google.protobuf
+ protobuf-java
+ ${protobuf-java.version}
+ test
+ true
+
+
org.sonatype.plexus
plexus-build-api
@@ -80,6 +94,12 @@
+
+
+ true
+ src/main/resources
+
+
maven-plugin-plugin
@@ -101,6 +121,7 @@
+
diff --git a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java
index e2c88b6c7e..64fe3e923a 100644
--- a/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java
+++ b/dubbo-maven-plugin/src/main/java/org/apache/dubbo/maven/plugin/protoc/DubboProtocCompilerMojo.java
@@ -17,6 +17,7 @@ package org.apache.dubbo.maven.plugin.protoc;
import org.apache.dubbo.maven.plugin.protoc.command.DefaultProtocCommandBuilder;
import org.apache.dubbo.maven.plugin.protoc.enums.DubboGenerateTypeEnum;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -31,8 +32,10 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.repository.RepositorySystem;
@@ -46,25 +49,33 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
import java.util.Set;
-import java.util.Arrays;
import static java.lang.String.format;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static org.codehaus.plexus.util.FileUtils.getFiles;
-@Mojo(name = "dubbo-protoc-compiler")
+@Mojo(
+ name = "compile",
+ defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+ requiresDependencyResolution = ResolutionScope.COMPILE,
+ threadSafe = true
+)
public class DubboProtocCompilerMojo extends AbstractMojo {
@Parameter(property = "protoSourceDir", defaultValue = "${basedir}/src/main/proto")
private File protoSourceDir;
@Parameter(property = "outputDir", defaultValue = "${project.build.directory}/generated-sources/protobuf/java")
private File outputDir;
- @Parameter(required = true, property = "dubboVersion", defaultValue = "${dubbo.version}")
+ @Parameter(required = false, property = "dubboVersion")
private String dubboVersion;
@Parameter(required = true, readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
private List remoteRepositories;
@@ -72,9 +83,11 @@ public class DubboProtocCompilerMojo extends AbstractMojo {
private String protocExecutable;
@Parameter(required = false, property = "protocArtifact")
private String protocArtifact;
+ @Parameter(required = false, property = "protocVersion")
+ private String protocVersion;
@Parameter(required = false, defaultValue = "${project.build.directory}/protoc-plugins")
private File protocPluginDirectory;
- @Parameter(required = true, property = "dubboGenerateType", defaultValue = "dubbo3")
+ @Parameter(required = true, property = "dubboGenerateType", defaultValue = "tri")
private String dubboGenerateType;
@Parameter(defaultValue = "${project}", readonly = true)
protected MavenProject project;
@@ -98,6 +111,31 @@ public class DubboProtocCompilerMojo extends AbstractMojo {
private final DubboProtocPluginWrapperFactory dubboProtocPluginWrapperFactory = new DubboProtocPluginWrapperFactory();
public void execute() throws MojoExecutionException, MojoFailureException {
+ Properties versionMatrix = new Properties();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ InputStream stream = loader.getResourceAsStream("version-matrix.properties");
+ try {
+ versionMatrix.load(stream);
+ } catch (IOException e) {
+ getLog().warn("Unable to load default version matrix", e);
+ }
+
+ if (dubboVersion == null) {
+ dubboVersion = versionMatrix.getProperty("dubbo.version");
+ }
+ if (protocVersion == null) {
+ protocVersion = versionMatrix.getProperty("protoc.version");
+ }
+ if (protocArtifact == null) {
+ final String osName = System.getProperty("os.name");
+ final String osArch = System.getProperty("os.arch");
+
+ final String detectedName = normalizeOs(osName);
+ final String detectedArch = normalizeArch(osArch);
+
+ protocArtifact = "com.google.protobuf:protoc:" + protocVersion + ":exe:" + detectedName + '-' + detectedArch;
+ }
+
if (protocExecutable == null && protocArtifact != null) {
final Artifact artifact = createProtocArtifact(protocArtifact);
final File file = resolveBinaryArtifact(artifact);
@@ -133,6 +171,39 @@ public class DubboProtocCompilerMojo extends AbstractMojo {
}
}
+ private static String normalizeOs(String value) {
+ value = normalize(value);
+ if (value.startsWith("linux")) {
+ return "linux";
+ }
+ if (value.startsWith("mac") || value.startsWith("osx")) {
+ return "osx";
+ }
+ if (value.startsWith("windows")) {
+ return "windows";
+ }
+
+ return "unknown";
+ }
+
+ private static String normalize(String value) {
+ if (value == null) {
+ return "";
+ }
+ return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
+ }
+
+ private static String normalizeArch(String value) {
+ value = normalize(value);
+ if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) {
+ return "x86_64";
+ }
+ if ("aarch64".equals(value)) {
+ return "aarch_64";
+ }
+ return "unknown";
+ }
+
public void linkProtoFilesToMaven() {
linkProtoSources();
linkGeneratedFiles();
diff --git a/dubbo-maven-plugin/src/main/resources/version-matrix.properties b/dubbo-maven-plugin/src/main/resources/version-matrix.properties
new file mode 100644
index 0000000000..10b01bab6e
--- /dev/null
+++ b/dubbo-maven-plugin/src/main/resources/version-matrix.properties
@@ -0,0 +1,2 @@
+dubbo.version=${dubbo.version}
+protoc.version=${protobuf-java.version}
diff --git a/dubbo-plugin/dubbo-compiler/README.md b/dubbo-plugin/dubbo-compiler/README.md
index f3e13e5a1a..3234723fb9 100644
--- a/dubbo-plugin/dubbo-compiler/README.md
+++ b/dubbo-plugin/dubbo-compiler/README.md
@@ -39,18 +39,18 @@ message HelloReply {
now dubbo support his own protoc plugin base on dubbo-maven-plugin
```xml
-
+
org.apache.dubbo
dubbo-maven-plugin
- 3.3.0
-
- 3.3.0
- dubbo3
- protoc
- com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}
-
+ ${dubbo.version}
+
+
+
+ compile
+
+
+
-
```
#### 3.generate file