本地编译运行nacos,当前环境:
组件 | 版本 |
---|---|
nacos | 1.4.1 |
os | Macos12.5.1 m1 pro |
idea | 2022.3 |
maven | 3.8.7 |
前期准备工作,可以参考 0101nacos本地编译运行-nacos-微服务架构,软件替换为macos版本即可
在clean install的时候,报错如下提示:
Could not find artifact com.google.protobuf:protoc:exe:osx-aarch_64:3.8.0 in alimaven (http://maven.aliyun.com/nexus/content/repositories/central)
[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.5.0:compile (default) on project nacos-consistency: Missing:
简单翻译就是在编译nacos-consistency模块时候,在maven仓库中找不到com.google.protobuf:protoc:osx-aarch_64:3.8.0
如下图所示:
首先我们去nacos-consistency模块pom.xml中看看它在哪里
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-java.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
然后搜索了下protobuf有什么作用?
Protocol Buffers(简称Protobuf) ,是Google出品的序列化框架,与开发语言无关,和平台无关,具有良好的可扩展性。Protobuf和所有的序列化框架一样,都可以用于数据存储、通讯协议 1 ^1 1。
这个东西我们现在只是有个概念,又不能随便删除,怎么解决编译报错呢?
继续搜索在如下地址https://github.com/grpc/grpc-java/issues/7690 找到问题解决方法
- 报错原因:protobuf没有提供MacBook m1 芯片 即arch架构的依赖包
- 解决方案:使用对应x86架构代替
具体实施:pom.xml架构变量${os.detected.classifier}替换为osx-x86_64,如果你是Gradle构建的做如下替换
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.14.0:osx-x86_64'
}
}
我用的maven,替换如下
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf-java.version}:exe:osx-x86_64</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc-java.version}:exe:osx-x86_64</pluginArtifact>
</configuration>
重新编译, 成功启动nacos
参考地址:
[1]<a href="Protobuf的介绍和使用[CP/OL]