ToB企服应用市场:ToB评测及商务社交产业平台

标题: Nacos源码 (1) 源码编译及idea环境 [打印本页]

作者: 立山    时间: 2023-7-31 15:59
标题: Nacos源码 (1) 源码编译及idea环境
本文介绍从gitee下载nacos源码,在本地编译,并导入idea进行本地调试。
从gitee下载源码

由于github访问速度慢,所以我选择使用gitee的镜像仓库:
  1. git clone https://gitee.com/mirrors/Nacos.git
复制代码
本文使用2.0.2版本,所以需要切换到2.0.2分支:
  1. cd Nacos
  2. git checkout 2.0.2
复制代码
创建一个自己的分支,用于保存笔记和代码注释:
  1. git checkout -b my-2.0.2
复制代码
本地编译
  1. mvn -Dmaven.test.skip=true -Drat.skip=true clean install
复制代码
构建发布包
  1. mvn -Prelease-nacos -Dmaven.test.skip=true -Drat.skip=true clean install -U
复制代码
这种构建方式会在distribution/target目录下生成nacos-server-2.0.2.zip包,从官网下载的就是这样的包。
但是会抛错:
  1. [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.1.0:repackage (default) on project nacos-console: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.1.0:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.1.0' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
复制代码
将工程使用的spring-boot-maven-plugin版本改成2.3.8.RELEASE版本即可:
  1. <plugin>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-maven-plugin</artifactId>
  4. <version>2.3.8.RELEASE</version>
  5. </plugin>
复制代码
idea开发环境

导入到idea

File -> Open导入即可。
启动console

找到console/src/main/java/com/alibaba/nacos/console/config/ConsoleConfig.java文件,修改PropertySource注解值:
  1. // @PropertySource("/application.properties")
  2. @PropertySource("classpath:application.properties")
  3. public class ConsoleConfig {
复制代码
/application.properties改为classpath:application.properties。
需要添加一些环境变量和参数:
如果需要自定义日志就使用--logging.config指定配置文件路径。
访问console

http://localhost:8848/nacos
用户名:nacos
密码:nacos

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4