下载代码
通过下载代码:
git clone git@github.com:alibaba/nacos.git
基于特定版本进行二次开发,比如这里基于2.2.2进行开发,NACOS 使用 tag 标记不同版本的代码,所以可以切换到特定版本的代码:
git checkout 2.2.2
基于这个版本创建本地分支进行开发:
git switch -c my-2.2.2
项目前端
NACOS 的前端项目使用 REACT 构建。项目启动命令位于console-ui/package.json。
启动项目:
npm start
此时使用的是console-ui/build/webpack.dev.conf.js中的配置信息运行, 如果需要修改对应的服务端配置,可以修改其中的代理配置:
proxy: [{
context: ['/'],
changeOrigin: true,
secure: false,
target: 'http://localhost:8848',
pathRewrite: {'^/v1' : '/nacos/v1', '^/v2' : '/nacos/v2'}
}]
项目编译:
npm run build
编译脚本会在编译后将生成的 html 等文件复制到 console 的静态资源目录下, 这样运行 console 模块时,会加载修改后的前端页面。
build 命令使用的配置文件为
console-ui/build/webpack.prod.conf.js。
项目后端
项目后端基于 SpringBoot 构建。项目启动的入口类位于 console/src/main/java/com/alibaba/nacos/Nacos.java。
项目后端的静态资源中包含前端页面文件,可以单独运行。除非你需要调试修改前端页面。
代码风格
项目打包插件中包含代码风格检查,因此后端代码需要遵守一些规则。
不能使用*进行批量引用,错误的示范:
import com.alibaba.nacos.common.utils.*;
必须使用单行引用,正确的示范:
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.common.utils.UrlUtils;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
在 idea 中可以右键,选择
修改为单行引用。
JavaDoc 注释首行必须有摘要,且必须以英文句号结尾,错误的示范:
/**
* This is a test class
*/
class Test {}
正确的示范:
/**
* This is a test class.
*/
class Test {}
方法前的 JavaDoc 注释同样要遵循这个规则。
禁止在方法前使用//注释,错误的示范:
// 测试用例(可删除)
public static void main(String[] args) {
// ...
}
正确的示范:
/**
* Test case.
*/
public static void main(String[] args) {
// ...
}
类/对象属性前要有空行,错误的示范:
public class ModifiableRequestWrapper extends HttpServletRequestWrapper {
// 维护可修改的参数Map
private final Map<String, String[]> parameterMap;
}
正确的示范:
public class ModifiableRequestWrapper extends HttpServletRequestWrapper {
// 维护可修改的参数Map
private final Map<String, String[]> parameterMap;
}
不能使用行尾注释,错误的示范:
public class CryptoUtil {
private static final String ALGORITHM = "AES/CBC/PKCS5Padding"; // 填充模式和前端Pkcs7一致(Java中是Pkcs5)
}
正确的示范:
public class CryptoUtil {
// 填充模式和前端Pkcs7一致(Java中是Pkcs5)
private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
}
字段注释只能使用 JavaDoc,不能使用//,错误的示范:
public class CryptoUtil {
// 填充模式和前端Pkcs7一致(Java中是Pkcs5)
private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
}
正确的示范:
public class CryptoUtil {
/**
* The fill pattern is the same as the frontend Pkcs7 (Pkcs5 in Java)
*/
private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
}
代码头部必须添加版权信息,正确的示范:
/*
* Copyright icexmoon.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.console;
//...
方法名不能有连续的大写字母出现
public static String decryptAES(String cipherText) {
// ...
}
正确的示范:
public static String decryptAes(String cipherText) {
// ...
}
打包
打包时需要勾选 maven 的release-nacos配置选项。 需要为生命周期的 install 选项添加虚拟机选项:
-Dmaven.test.skip=true -Dcheckstyle.skip=true -Drat.skip=true -Denforcer.skip=true -Dfile.encoding=UTF-8
注意:nacos 打包时需要执行
maven install,而非通常的maven package。
打包成功后,会在distribution/target目录下生成打包结果, 包含可以直接发行的压缩包*.tar.gz和*.zip。
也可以直接使用distribution/target/nacos-server-2.2.2

文章评论