これは、なにをしたくて書いたもの?
以前、Groovyでこういうスクリプトを書きました。
Nexus 3向けにMavenのローカルリポジトリのファイルをリモートリポジトリにデプロイするスクリプトを書く - CLOVER🍀
最近ではGroovyを使っていないので、こういうのはPythonでやろうかなと思って書き直すことにしました。
内容を思い出すことも兼ねて。
あらためて、なにがしたいの?
Apache Mavenのローカルリポジトリーなどにあるアーティファクトを、Sonatype Nexus Repositoryのようなインハウスリポジトリーに
一気にデプロイしたいというのがやりたいことです。
単一のアーティファクトリであれば、Apache Maven Deploy Pluginのdeploy:deploy-fileゴールで実行できます。
Apache Maven Deploy Plugin – deploy:deploy-file
ただ、これだとアーティファクトが多くなると面倒なので、スクリプト化したいなということで。
今回は以下の内容を行います。
- Sonatype Nexus RepositoryでMavenリポジトリーを作成する
- Spring Initializrでサンプルアプリケーションを作成し、依存関係やソースコード、Javadocを収集する
- ローカルリポジトリーに収集したアーティファクトをどこかローカルディレクトリーにコピーし、スクリプトを使って一括アップロード
ローカルリポジトリーからコピーする1ステップが入っていますが、これはdeploy:deploy-fileゴールがローカルリポジトリーにあるファイルを
直接デプロイすることを許さないからです。
if (file.equals(artifactLocalFile)) { throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file); }
これを避けるためにはコピーするか、-Dmaven.repo.localを使って別のディレクトリーをローカルリポジトリーとしてファイルを収集しましょう。
こんなお題でやってみます。
環境
今回の環境はこちら。
Sonatype Nexus Repositoryのバージョンは3.85.0-03とします。また192.168.0.6で動作しているものとします。
$ python3 --version Python 3.12.3
$ mvn --version Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b) Maven home: $HOME/.sdkman/candidates/maven/current Java version: 21.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64 Default locale: ja_JP, platform encoding: UTF-8 OS name: "linux", version: "6.8.0-86-generic", arch: "amd64", family: "unix"
Sonatype Nexus RepositoryのMavenリポジトリーはTerraformで作成します。
$ terraform version Terraform v1.13.4 on linux_amd64
Sonatype Nexus RepositoryにMavenリポジトリーを作成する
まずはSonatype Nexus RepositoryにMavenリポジトリーを作成しましょう。
こんなTerraform構成ファイルを用意。
main.tf
terraform { required_version = "v1.13.4" required_providers { nexus = { source = "datadrivers/nexus" version = "2.6.0" } } } provider "nexus" { username = "admin" password = "password" url = "http://192.168.0.6:8081" insecure = true } resource "nexus_repository_maven_hosted" "hosted" { name = "my-maven-hosted-repo" online = true maven { layout_policy = "STRICT" version_policy = "RELEASE" content_disposition = "INLINE" } storage { blob_store_name = "default" strict_content_type_validation = true write_policy = "ALLOW_ONCE" } } resource "nexus_repository_maven_proxy" "proxy" { name = "my-maven-proxy-repo" online = true proxy { remote_url = "https://repo1.maven.org/maven2/" content_max_age = -1 metadata_max_age = 1440 } maven { layout_policy = "STRICT" version_policy = "RELEASE" content_disposition = "INLINE" } storage { blob_store_name = "default" strict_content_type_validation = true } http_client { auto_block = true blocked = false } negative_cache { enabled = true ttl = 1440 } } resource "nexus_repository_maven_group" "group" { name = "my-maven-group-repo" online = true group { member_names = [ nexus_repository_maven_hosted.hosted.name, nexus_repository_maven_proxy.proxy.name, ] } storage { blob_store_name = "default" strict_content_type_validation = true } }
今回はHostedリポジトリーだけがあればいいのですが、ひととおり用意することにしました。
作成。
$ terraform init $ terraform apply
サンプルアプリケーションの作成と、依存ライブラリーの収集
Spring Initializrでサンプルアプリケーションを作成します。
$ curl -s https://start.spring.io/starter.tgz \ -d bootVersion=3.5.7 \ -d javaVersion=21 \ -d type=maven-project \ -d name=demo \ -d groupId=org.littlewings \ -d artifactId=demo \ -d version=0.0.1-SNAPSHOT \ -d packageName=org.littlewings.spring.demo \ -d dependencies=web,jdbc,h2 \ -d baseDir=demo | tar zxvf -
ディレクトリー内に移動して
$ cd demo
$ mvn dependency:resolve-sources $ mvn dependency:resolve -Dclassifier=javadoc
最初からローカルリポジトリーを使わない場合は、-Dmaven.repo.localを指定してデフォルトのローカルリポジトリーとは別のディレクトリーで
収集するようにしてください。
org/springframeworkを確認。今回はこの配下をデプロイすることにしましょう。
$ tree ~/.m2/repository/org/springframework
$HOME/.m2/repository/org/springframework
├── amqp
│ └── spring-amqp-bom
│ └── 3.2.8
│ ├── _remote.repositories
│ ├── spring-amqp-bom-3.2.8.pom
│ └── spring-amqp-bom-3.2.8.pom.sha1
├── batch
│ └── spring-batch-bom
│ └── 5.2.4
│ ├── _remote.repositories
│ ├── spring-batch-bom-5.2.4.pom
│ └── spring-batch-bom-5.2.4.pom.sha1
├── boot
│ ├── spring-boot
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-3.5.7-javadoc.jar
│ │ ├── spring-boot-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-3.5.7-sources.jar
│ │ ├── spring-boot-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-3.5.7.jar
│ │ ├── spring-boot-3.5.7.jar.sha1
│ │ ├── spring-boot-3.5.7.pom
│ │ └── spring-boot-3.5.7.pom.sha1
│ ├── spring-boot-autoconfigure
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-autoconfigure-3.5.7-javadoc.jar
│ │ ├── spring-boot-autoconfigure-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-autoconfigure-3.5.7-sources.jar
│ │ ├── spring-boot-autoconfigure-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-autoconfigure-3.5.7.jar
│ │ ├── spring-boot-autoconfigure-3.5.7.jar.sha1
│ │ ├── spring-boot-autoconfigure-3.5.7.pom
│ │ └── spring-boot-autoconfigure-3.5.7.pom.sha1
│ ├── spring-boot-dependencies
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-dependencies-3.5.7.pom
│ │ └── spring-boot-dependencies-3.5.7.pom.sha1
│ ├── spring-boot-maven-plugin
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-maven-plugin-3.5.7.jar
│ │ ├── spring-boot-maven-plugin-3.5.7.jar.sha1
│ │ ├── spring-boot-maven-plugin-3.5.7.pom
│ │ └── spring-boot-maven-plugin-3.5.7.pom.sha1
│ ├── spring-boot-starter
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-3.5.7-sources.jar
│ │ ├── spring-boot-starter-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-3.5.7.jar
│ │ ├── spring-boot-starter-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-3.5.7.pom
│ │ └── spring-boot-starter-3.5.7.pom.sha1
│ ├── spring-boot-starter-jdbc
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-jdbc-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-jdbc-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-jdbc-3.5.7-sources.jar
│ │ ├── spring-boot-starter-jdbc-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-jdbc-3.5.7.jar
│ │ ├── spring-boot-starter-jdbc-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-jdbc-3.5.7.pom
│ │ └── spring-boot-starter-jdbc-3.5.7.pom.sha1
│ ├── spring-boot-starter-json
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-json-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-json-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-json-3.5.7-sources.jar
│ │ ├── spring-boot-starter-json-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-json-3.5.7.jar
│ │ ├── spring-boot-starter-json-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-json-3.5.7.pom
│ │ └── spring-boot-starter-json-3.5.7.pom.sha1
│ ├── spring-boot-starter-logging
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-logging-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-logging-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-logging-3.5.7-sources.jar
│ │ ├── spring-boot-starter-logging-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-logging-3.5.7.jar
│ │ ├── spring-boot-starter-logging-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-logging-3.5.7.pom
│ │ └── spring-boot-starter-logging-3.5.7.pom.sha1
│ ├── spring-boot-starter-parent
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-parent-3.5.7.pom
│ │ └── spring-boot-starter-parent-3.5.7.pom.sha1
│ ├── spring-boot-starter-test
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-test-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-test-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-test-3.5.7-sources.jar
│ │ ├── spring-boot-starter-test-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-test-3.5.7.jar
│ │ ├── spring-boot-starter-test-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-test-3.5.7.pom
│ │ └── spring-boot-starter-test-3.5.7.pom.sha1
│ ├── spring-boot-starter-tomcat
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-tomcat-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-tomcat-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-tomcat-3.5.7-sources.jar
│ │ ├── spring-boot-starter-tomcat-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-tomcat-3.5.7.jar
│ │ ├── spring-boot-starter-tomcat-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-tomcat-3.5.7.pom
│ │ └── spring-boot-starter-tomcat-3.5.7.pom.sha1
│ ├── spring-boot-starter-web
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-starter-web-3.5.7-javadoc.jar
│ │ ├── spring-boot-starter-web-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-starter-web-3.5.7-sources.jar
│ │ ├── spring-boot-starter-web-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-starter-web-3.5.7.jar
│ │ ├── spring-boot-starter-web-3.5.7.jar.sha1
│ │ ├── spring-boot-starter-web-3.5.7.pom
│ │ └── spring-boot-starter-web-3.5.7.pom.sha1
│ ├── spring-boot-test
│ │ └── 3.5.7
│ │ ├── _remote.repositories
│ │ ├── spring-boot-test-3.5.7-javadoc.jar
│ │ ├── spring-boot-test-3.5.7-javadoc.jar.sha1
│ │ ├── spring-boot-test-3.5.7-sources.jar
│ │ ├── spring-boot-test-3.5.7-sources.jar.sha1
│ │ ├── spring-boot-test-3.5.7.jar
│ │ ├── spring-boot-test-3.5.7.jar.sha1
│ │ ├── spring-boot-test-3.5.7.pom
│ │ └── spring-boot-test-3.5.7.pom.sha1
│ └── spring-boot-test-autoconfigure
│ └── 3.5.7
│ ├── _remote.repositories
│ ├── spring-boot-test-autoconfigure-3.5.7-javadoc.jar
│ ├── spring-boot-test-autoconfigure-3.5.7-javadoc.jar.sha1
│ ├── spring-boot-test-autoconfigure-3.5.7-sources.jar
│ ├── spring-boot-test-autoconfigure-3.5.7-sources.jar.sha1
│ ├── spring-boot-test-autoconfigure-3.5.7.jar
│ ├── spring-boot-test-autoconfigure-3.5.7.jar.sha1
│ ├── spring-boot-test-autoconfigure-3.5.7.pom
│ └── spring-boot-test-autoconfigure-3.5.7.pom.sha1
├── data
│ └── spring-data-bom
│ └── 2025.0.5
│ ├── _remote.repositories
│ ├── spring-data-bom-2025.0.5.pom
│ └── spring-data-bom-2025.0.5.pom.sha1
├── integration
│ └── spring-integration-bom
│ └── 6.5.3
│ ├── _remote.repositories
│ ├── spring-integration-bom-6.5.3.pom
│ └── spring-integration-bom-6.5.3.pom.sha1
├── pulsar
│ └── spring-pulsar-bom
│ └── 1.2.11
│ ├── _remote.repositories
│ ├── spring-pulsar-bom-1.2.11.pom
│ └── spring-pulsar-bom-1.2.11.pom.sha1
├── restdocs
│ └── spring-restdocs-bom
│ └── 3.0.5
│ ├── _remote.repositories
│ ├── spring-restdocs-bom-3.0.5.pom
│ └── spring-restdocs-bom-3.0.5.pom.sha1
├── security
│ └── spring-security-bom
│ └── 6.5.6
│ ├── _remote.repositories
│ ├── spring-security-bom-6.5.6.pom
│ └── spring-security-bom-6.5.6.pom.sha1
├── session
│ └── spring-session-bom
│ └── 3.5.3
│ ├── _remote.repositories
│ ├── spring-session-bom-3.5.3.pom
│ └── spring-session-bom-3.5.3.pom.sha1
├── spring-aop
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-aop-6.2.12-javadoc.jar
│ ├── spring-aop-6.2.12-javadoc.jar.sha1
│ ├── spring-aop-6.2.12-sources.jar
│ ├── spring-aop-6.2.12-sources.jar.sha1
│ ├── spring-aop-6.2.12.jar
│ ├── spring-aop-6.2.12.jar.sha1
│ ├── spring-aop-6.2.12.pom
│ └── spring-aop-6.2.12.pom.sha1
├── spring-beans
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-beans-6.2.12-javadoc.jar
│ ├── spring-beans-6.2.12-javadoc.jar.sha1
│ ├── spring-beans-6.2.12-sources.jar
│ ├── spring-beans-6.2.12-sources.jar.sha1
│ ├── spring-beans-6.2.12.jar
│ ├── spring-beans-6.2.12.jar.sha1
│ ├── spring-beans-6.2.12.pom
│ └── spring-beans-6.2.12.pom.sha1
├── spring-context
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-context-6.2.12-javadoc.jar
│ ├── spring-context-6.2.12-javadoc.jar.sha1
│ ├── spring-context-6.2.12-sources.jar
│ ├── spring-context-6.2.12-sources.jar.sha1
│ ├── spring-context-6.2.12.jar
│ ├── spring-context-6.2.12.jar.sha1
│ ├── spring-context-6.2.12.pom
│ └── spring-context-6.2.12.pom.sha1
├── spring-core
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-core-6.2.12-javadoc.jar
│ ├── spring-core-6.2.12-javadoc.jar.sha1
│ ├── spring-core-6.2.12-sources.jar
│ ├── spring-core-6.2.12-sources.jar.sha1
│ ├── spring-core-6.2.12.jar
│ ├── spring-core-6.2.12.jar.sha1
│ ├── spring-core-6.2.12.pom
│ └── spring-core-6.2.12.pom.sha1
├── spring-expression
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-expression-6.2.12-javadoc.jar
│ ├── spring-expression-6.2.12-javadoc.jar.sha1
│ ├── spring-expression-6.2.12-sources.jar
│ ├── spring-expression-6.2.12-sources.jar.sha1
│ ├── spring-expression-6.2.12.jar
│ ├── spring-expression-6.2.12.jar.sha1
│ ├── spring-expression-6.2.12.pom
│ └── spring-expression-6.2.12.pom.sha1
├── spring-framework-bom
│ ├── 5.3.39
│ │ ├── _remote.repositories
│ │ ├── spring-framework-bom-5.3.39.pom
│ │ └── spring-framework-bom-5.3.39.pom.sha1
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-framework-bom-6.2.12.pom
│ └── spring-framework-bom-6.2.12.pom.sha1
├── spring-jcl
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-jcl-6.2.12-javadoc.jar
│ ├── spring-jcl-6.2.12-javadoc.jar.sha1
│ ├── spring-jcl-6.2.12-sources.jar
│ ├── spring-jcl-6.2.12-sources.jar.sha1
│ ├── spring-jcl-6.2.12.jar
│ ├── spring-jcl-6.2.12.jar.sha1
│ ├── spring-jcl-6.2.12.pom
│ └── spring-jcl-6.2.12.pom.sha1
├── spring-jdbc
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-jdbc-6.2.12-javadoc.jar
│ ├── spring-jdbc-6.2.12-javadoc.jar.sha1
│ ├── spring-jdbc-6.2.12-sources.jar
│ ├── spring-jdbc-6.2.12-sources.jar.sha1
│ ├── spring-jdbc-6.2.12.jar
│ ├── spring-jdbc-6.2.12.jar.sha1
│ ├── spring-jdbc-6.2.12.pom
│ └── spring-jdbc-6.2.12.pom.sha1
├── spring-test
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-test-6.2.12-javadoc.jar
│ ├── spring-test-6.2.12-javadoc.jar.sha1
│ ├── spring-test-6.2.12-sources.jar
│ ├── spring-test-6.2.12-sources.jar.sha1
│ ├── spring-test-6.2.12.jar
│ ├── spring-test-6.2.12.jar.sha1
│ ├── spring-test-6.2.12.pom
│ └── spring-test-6.2.12.pom.sha1
├── spring-tx
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-tx-6.2.12-javadoc.jar
│ ├── spring-tx-6.2.12-javadoc.jar.sha1
│ ├── spring-tx-6.2.12-sources.jar
│ ├── spring-tx-6.2.12-sources.jar.sha1
│ ├── spring-tx-6.2.12.jar
│ ├── spring-tx-6.2.12.jar.sha1
│ ├── spring-tx-6.2.12.pom
│ └── spring-tx-6.2.12.pom.sha1
├── spring-web
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-web-6.2.12-javadoc.jar
│ ├── spring-web-6.2.12-javadoc.jar.sha1
│ ├── spring-web-6.2.12-sources.jar
│ ├── spring-web-6.2.12-sources.jar.sha1
│ ├── spring-web-6.2.12.jar
│ ├── spring-web-6.2.12.jar.sha1
│ ├── spring-web-6.2.12.pom
│ └── spring-web-6.2.12.pom.sha1
├── spring-webmvc
│ └── 6.2.12
│ ├── _remote.repositories
│ ├── spring-webmvc-6.2.12-javadoc.jar
│ ├── spring-webmvc-6.2.12-javadoc.jar.sha1
│ ├── spring-webmvc-6.2.12-sources.jar
│ ├── spring-webmvc-6.2.12-sources.jar.sha1
│ ├── spring-webmvc-6.2.12.jar
│ ├── spring-webmvc-6.2.12.jar.sha1
│ ├── spring-webmvc-6.2.12.pom
│ └── spring-webmvc-6.2.12.pom.sha1
└── ws
└── spring-ws-bom
└── 4.1.2
├── _remote.repositories
├── spring-ws-bom-4.1.2.pom
└── spring-ws-bom-4.1.2.pom.sha1
82 directories, 242 files
この配下を適当なディレクトリーにコピーしておきます。
$ mkdir -p local-repo/org/springframework $ cp -Rp ~/.m2/repository/org/springframework/* local-repo/org/springframework/
アーティファクトをデプロイするスクリプトを書く
それではアーティファクトをデプロイするスクリプトを書きます。
取り回しを考えると、指定のディレクトリー配下にあるファイルを探索するものがよいかなと思います。
作成したスクリプトはこちら。
deploy_maven_artifact.py
from pathlib import Path import os import subprocess import sys target_dir = sys.argv[1] repository_id = "my-maven-hosted-repo" repository_url = "http://192.168.0.6:8081/repository/my-maven-hosted-repo" failure_command = [] def deploy_artifacts_in_dir(dir: str) -> None: for root, _, files in os.walk(dir): artifacts = find_artifact_files(root, files) if len(artifacts) > 0: command = ["mvn", "deploy:deploy-file", f"-Durl={repository_url}", f"-DrepositoryId={repository_id}"] if "pom" in artifacts: command.append(f"-DpomFile={artifacts['pom']}") if "artifact" in artifacts: command.append(f"-Dfile={artifacts['artifact']}") elif "pom" in artifacts: command.append(f"-Dfile={artifacts['pom']}") if "javadoc" in artifacts: command.append(f"-Djavadoc={artifacts['javadoc']}") if "sources" in artifacts: command.append(f"-Dsources={artifacts['sources']}") print(f"command = {command}") result = subprocess.run(command) if result.returncode != 0: failure_command.append(command) def find_artifact_files(dir: str, files: list[str]) -> dict[str, str]: path = Path(dir) artifacts = {} for file in files: f = str(path / file) if f.endswith(".pom"): artifacts["pom"] = f elif f.endswith("-javadoc.jar"): artifacts["javadoc"] = f elif f.endswith("-sources.jar"): artifacts["sources"] = f elif f.endswith(".jar"): artifacts["artifact"] = f return artifacts deploy_artifacts_in_dir(target_dir) if len(failure_command): print("Failure Commans:") for command in failure_command: print(command)
指定のディレクトリー内のファイルを見て、以下のコマンドを構築して実行するスクリプトです。
※イメージです
## JARアーティファクトの場合
mvn deploy:deploy-file \
-Durl=[リポジトリーのURL] \
-DrepositoryId=[リポジトリーのID] \
-DpomFile=[pom.xmlのパス] \
-Dfile=[アーティファクトのパス] \
-Djavadoc=[Javadoc JARファイルへのパス] \
-Dsources=[Sources JARファイルへのパス]
## pomアーティファクトの場合
mvn deploy:deploy-file \
-Durl=[リポジトリーのURL] \
-DrepositoryId=[リポジトリーのID] \
-DpomFile=[pom.xmlのパス] \
-Dfile=[pom.xmlのパス]
classfierなどを考えるとカバーしきれないパターンはたくさんあると思いますが、シンプルなものであればこれでよいでしょう。
-DrepositoryIdに指定するのは、settings.xmlのserverのidです。
というわけで、こんなsettings.xmlを用意。
$HOME/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> <servers> <server> <id>my-maven-hosted-repo</id> <username>admin</username> <password>password</password> </server> </servers> </settings>
実行。
$ python3 deploy_maven_artifact.py local-repo/org/springframework
うまくデプロイできたようです。

おわりに
Sonatype Nexus Repository 3へ、ローカルディレクトリーのアーティファクトをデプロイするPythonスクリプトを書いてみました。
久しぶりにdeploy:deploy-fileゴールを実行してみましたが、ローカルリポジトリーからデプロイできないことを完全に忘れていてちょっと
ハマりました。
またソースコードやJavadocの収集方法、以前書いたスクリプトからdeploy:deploy-fileゴールに指定するプロパティーの見直しなどもできて
よかったかなと思います。