Skip to content

Instantly share code, notes, and snippets.

@m-serag-lab
Created November 22, 2022 21:04
Show Gist options
  • Save m-serag-lab/adf41e89e967646b22047bfe2145ab14 to your computer and use it in GitHub Desktop.
Save m-serag-lab/adf41e89e967646b22047bfe2145ab14 to your computer and use it in GitHub Desktop.
Python script to upload mass dependencies to nexus
import subprocess, os
# Root path for dependencies (without / in the end)
ROOT_PATH = "/root/.m2/repository"
NEXUS_USERNAME="admin"
NEXUS_PASSWORD="123456"
NEXUS_PROTOCOL="http"
NEXUS_URL="localhost:7000/repository/nexus-mvn-repo-release/"
def _get_details(file_path: str):
version_end = file_path.rindex("/")
version_start = file_path.rindex("/", 0, version_end)
result = {}
result["version"] = file_path[version_start + 1:version_end]
artifact_start = file_path.rindex("/", 0, version_start)
result["artifact"] = file_path[artifact_start + 1:version_start]
result["group"] = file_path[len(ROOT_PATH)+1:artifact_start].replace("/", ".")
return result
def process_file(file_path):
path_details = _get_details(file_path)
group = path_details["group"]
artifact = path_details["artifact"]
version = path_details["version"]
print(f"group: [{group}], artifact: [{artifact}], version: [{version}], path: [{file_path}]")
mvn_command = f'mvn deploy:deploy-file -D"groupId={group}" -D"artifactId={artifact}" -D"version={version}" -D"packaging=jar" -D"file={file_path}" -DgeneratePom=true -DupdateReleaseInfo=true -Durl="{NEXUS_PROTOCOL}://{NEXUS_USERNAME}:{NEXUS_PASSWORD}@{NEXUS_URL}"'
print(mvn_command)
subprocess.call(mvn_command, shell=True)
for root, dirs, files in os.walk(ROOT_PATH):
for file in files:
if file.endswith(".jar"):
process_file(os.path.join(root, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment