LoginSignup
2
2

More than 5 years have passed since last update.

Mavenでpom.xmlを使用せずにNexusにdeploy

Posted at

Mavenのpackagingが[war]なpom.xmlがあって、warとjarを一緒に出力しててdeploy-pluginでNexusにjarもdeployしようとしたけどうまくいかなかったのでシェルを作った。

  1. deployしたjarは、消してから登録するので同一バージョンで何度でもdeployできる
  2. mvn package を実行してtargetディレクトリ配下にjarファイルが存在することが前提

手順

以下のシェルスクリプトでpom.xmlから情報を取得してNexusにjarをdeployする。

deploy-jar.sh
#!/bin/bash
nexusUser=Nexusのadmin
nexusPass=Nexusのadminパスワード
myGroupId=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/groupId/text()" -`
myArtifactId=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/artifactId/text()" -`
myVersion=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/version/text()" -`
myReleaseUrl=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/distributionManagement/repository/url/text()" -`

curl --request DELETE --write "%{http_code} %{url_effective}\\n" \
     --user "${nexusUser}:${nexusPass}" --output /dev/null --silent \
     ${myReleaseUrl}${myGroupId//./\/}/${myArtifactId}/${myVersion}

mvn deploy:deploy-file \
    -DgroupId=${myGroupId} -DartifactId=${myArtifactId} -Dversion=${myVersion} \
    -Dpackaging=jar -Dfile=./target/${myArtifactId}.jar -DgeneratePom=true \
    -DrepositoryId=releases -Durl=${myReleaseUrl}

説明1

myGroupId=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/groupId/text()" -`
xmllintコマンドをpom.xmlに直接使うと[XPath set is empty]になるのでネームスペースを無視するように置換する

説明2

curl --request DELETE --write "%{http_code} %{url_effective}\\n"
curlを使って、NexusのリポジトリURLに対してDELETEコマンドを送信する
%{http_code} curlを実行したリターンコードを出力
%{url_effective} curlを実行したURLを出力

説明3

mvn deploy:deploy-file
pom.xmlから取得した各種パラメータでmvn deployコマンドを実行

※pom.xmlを使用せずってタイトルだけど、pom.xmlがあってpackageが実行してあることが前提 (´・ω・`)

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2