LoginSignup
47
55

More than 5 years have passed since last update.

mavenのインハウスリポジトリを作るよ

Posted at

たまに、mavenのリポジトリに無いライブラリとかありますよね?
または、既存ライブラリをオレオレ用にどうしても修正しなくなってはならなくなってしまったとき。

install:install-file

そんな時はローカルのjar に対して、

mvn install:install-file -Dfile="httpclient/r10949/httpclient.jar" -DgroupId=new.gyu -DartifactId=httpclient -Dversion=r10949 -Dpackaging=jar

こんな感じにローカルにインストールすることで依存性が解決されます。

一人の時はこれでいいのですが、人数が増えてくるとメンバーに上記の手順をやらせるとかちょっとダサい。
そんな時には自社内にインハウスリポジトリを作るのがオススメです。

インハウスリポジトリを使う

インハウスリポジトリをつくる

インハウスリポジトリを作るのは簡単です。
普通にhttpアクセスできる場所を作ればOKです。

mvn.conf
Alias /mvnrepo/ "/home/mvn/repo/" 

<Directory "/home/mvn/repo">
    Options Indexes
    Order allow,deny
    Allow from all
</Directory>

例えばこんな感じ。

インハウスリポジトリにデプロイするための設定

デプロイ方法は http put ,WebDAV,SCP色々有るみたいですが、フツーscpでいいでしょう。

既存ライブラリを修正する場合

mvnプロジェクト化されているものをであればpom.xmlを修正します。

pom.xml
  <distributionManagement>
    <repository>
      <id>my.repo</id>
      <name>Inhouse</name>
      <url>scp://myserver/home/mvn/repo</url>
    </repository>
  </distributionManagement>

     :
<build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh</artifactId>
        <version>2.5</version>
      </extension>
    </extensions>
</build>

※ wagon というプラグインを使わないとSCPでのアップロードはできないようで。。

有り物のjarを登録したい場合

mvn deploy:deploy-file -Durl=scp://xxx.xxx/home/mvn/repo \
                       -DrepositoryId=my.repo \
                       -Dfile=./httpclient.jar \
                       -DgroupId=new.gyu\
                       -DartifactId=httpclient \
                       -Dversion=r10949  \
                       -Dpackaging=jar

これでインハウスリポジトリ用のサーバにアップロードされます。

インハウスリポジトリを使う

俺のプロダクトのpom.xml に

pom.xml
<repositories>
        <repository>
            <id>my.repo</id>
            <name> Inhouse</name>
            <url>http://xxx.xxx.xx/mvnrepo/</url>
        </repository>
</repositories>

を足せば、このリポジトリも探しに行ってくれます。

47
55
5

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
47
55