背景是在家里写代码,有时候想发布一个组件。
看起来有几个选项,要么是发布到github,要么是发布到jetpat。
但是我的组件又不太想对所有人开放。
部署一个maven center需要几个g的内存,我的云服务器只有1C1G,完全带不动这么高的配置。
所以这是本文的方法用nginx替代maven.
发布到简易版本maven
step 1, 发布到本地文件
java
apply plugin: 'maven-publish'
def build_data = new Date().format('yyyyMMddHH')
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
def releaseComponent = components.findByName("release")
if (releaseComponent != null) {
from releaseComponent
}
groupId = "org.yeshen"
artifactId = "tcpdump"
version = "1.0.${build_data}"
}
}
repositories {
maven {
url "file://" + projectDir + "../../../export"
}
}
}
}
apply from: rootProject.file('gradle/git-publish.gradle')
./gradlew :libtcpdump:publish
step 2 拷贝文件到nginx目录
sh
scp -r ../export/* ${ssh_server_path}
step 3 使用
maven {
url = uri("https://${你的域名}$/${路径}")
}
鉴权
生成密码文件
sudo apt update
sudo apt install apache2-utils
openssl rand -base64 16
# 获取随机密码
# 创建文件并添加用户 yeshen(交互式输入密码)
sudo htpasswd -c /etc/nginx/.htpasswd yeshen
# 填入上面生成的随机密码
nginx配置访问权限
配置
location /maven {
auth_basic "Maven Repository";
auth_basic_user_file /etc/nginx/.htpasswd;
autoindex on;
}
生效配置
sh
sudo nginx -t
sudo systemctl restart nginx
使用
maven {
url = uri("https://${domain}/maven")
credentials {
username = 'yeshen' // 上面的用户名
password = 'xxxxx' // 上面生成的随机密码
}
}