Dubbo源码构建
前言
最近一直在倒腾Dubbo相关的事情,闲来无事准备研究一下Dubbo的源码。在网上找了几篇Dubbo源码构建的文章发现没有解决自己的问题,所以记录一下构建过程中自己踩的坑。
环境准备
- MacOS (M1 Apple Silicon)
- Jetbrains IDEA
- JDK:1.8
- maven:apache-maven-3.8.3
- ZooKeeper 3.5.0
下载源码&编译
进入到GitHub中的Dubbo官网,点击tags标签,选择你想研究的版本进行切换

然后将对应版本的Dubbo源码下载,不要试图使用IDEA直接clone,我挂着梯子速度还是不行。直接下载到本地,然后解压即可。我下载的是2.7.15版本。

接着使用IDEA直接导入即可

然后等待IDEA导入相关依赖,在这个过程中出现这个错误:Cannot resolve io.grpc:grpc-api:1.31.1

然后我找了半天,终于在StackOverFlow找到解决办法,指路Cannot resolve io.grpc:grpc-api:1.31.1,这里面有两个办法,高赞的那个没能解决,我采用的是在依赖管理中覆盖grpc-core的办法,在dubbo-2.7.15的父pom.xml中引入如下依赖:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.6.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
</dependency>
</dependencies>
然后reImport一下pom.xml文件即可

接着打开IDEA的maven工具栏,找到dubbo-parent(root),先点击clean,完成后,点击上方的⚡️按钮,开启跳过test编译,然后点击build

接着会遇到一个报错,Could not find artifact com.google.protobuf:protoc:exe:osx-aarch_64:3.7.1 in alimaven (http://maven.aliyun.com/nexus/content/groups/public/)

谷歌一圈,发现好像是因为M1芯片的MBP不兼容,所以出现了报错,最后找到了这个解决办法,com.google.protobuf:protoc:exe:osx-aarch_64:3.7.1,需要在maven的setting.xml的文件中添加上针对M1芯片的profile,如下所示:
<settings>
<activeProfiles>
<activeProfile>
apple-silicon
</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>apple-silicon</id>
<properties>
<os.detected.classifier>osx-x86_64</os.detected.classifier>
</properties>
</profile>
</profiles>
</settings>
然后重新执行build,最后编译成功。

测试&日志
接着找到dubbo-demo中的dubbo-demo-annotation-provider,如下所示:

为了方便了解Dubbo的启动流程,修改log4j.properties,将org.apache.dubbo包及其子包的日志等级设置为debug。

接着启动本地的zookeeper,如下所示:

然后启动Application中的main方法

至此Dubbo源码构建结束。

浙公网安备 33010602011771号