背景:外包类项目开发时是调用的公司maven仓库进行开发,交付后需要将maven仓库转移到客户环境。
原理:1、打开idea运行源代码,将maven包下载到本地仓库,
2、下载包所在目录中执行脚本将本地仓库的maven包上传到客户nexus文章来源:https://www.toymoban.com/news/detail-795519.html
脚本代码如下:文章来源地址https://www.toymoban.com/news/detail-795519.html
# -*- coding: utf-8 -*-
import os
import subprocess
# releases仓库地址
REPO_URL_RELEASES = "http://192.168.2.230:8081/repository/hosted-release/"
# snapshots仓库地址
REPO_URL_SNAPSHOTS = "http://192.168.2.230:8081/repository/hosted-snapshot/"
USERNAME = "admin"
PASSWORD = "admin"
def upload_files(repo_url, username, password):
for root, dirs, files in os.walk("."):
for file_name in files:
if file_name.endswith(".sh"):
continue
if file_name.startswith("."):
continue
if "-SNAPSHOT" in root:
continue
if "_remote.repositories" in file_name:
continue
if file_name.startswith("^archetype-catalog.xml") or file_name.startswith("^maven-metadata-local.xml") or file_name.startswith("^maven-metadata-deployment.xml"):
continue
file_path = os.path.join(root, file_name)
upload_url = os.path.join(repo_url, file_path[2:])
curl_command = ["curl", "-u", "{}:{}".format(username, password), "-X", "PUT", "-v", "-T", file_path, upload_url]
try:
subprocess.check_call(curl_command)
except subprocess.CalledProcessError as e:
print("Failed to upload {}: {}".format(file_path, e))
else:
print("Uploaded: {}".format(file_path))
if __name__ == "__main__":
print("Uploading releases...")
upload_files(REPO_URL_RELEASES, USERNAME, PASSWORD)
print("\nUploading snapshots...")
upload_files(REPO_URL_SNAPSHOTS, USERNAME, PASSWORD)
到了这里,关于使用Python批量上传本地maven库到nexus的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!