010101protobuf插件编译报错-nacos本地编译运行-macos_m1踩坑系列

本地编译运行nacos,当前环境:

组件版本
nacos1.4.1
osMacos12.5.1 m1 pro
idea2022.3
maven3.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]

[2]protoc-gen-grpc-java not available on apple m1 [CP/OL]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gaog2zh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值