Java
Maven

ローカルのjarをmavenのpom.xmlに追加する方法

はじめに

公開リポジトリを作るのはjenkinsを使えば楽だが、jenkinsを用意するのが面倒。
てなわけで、ローカル用のリポジトリを作ってやれば良い。

ライブラリの方にて

mvn install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.haniokasai:cpulimitController:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 44, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building cpulimitController 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cpulimitController ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ cpulimitController ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ cpulimitController ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory Z:\users\doc\GitHub\cpulimitController\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ cpulimitController ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ cpulimitController ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ cpulimitController ---
[INFO]
[INFO] --- maven-shade-plugin:2.4.3:shade (default) @ cpulimitController ---
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing Z:\users\doc\GitHub\cpulimitController\target\cpulimitController-1.0-SNAPSHOT.jar with Z:\users\doc\GitHub\cpulimitController\target\cpulimitController-1.0-SNAPSHOT-shaded.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ cpulimitController ---
[INFO] Installing Z:\users\doc\GitHub\cpulimitController\target\cpulimitController-1.0-SNAPSHOT.jar to C:\Users\何某\.m2\repository\com\haniokasai\cpulimitController\1.0-SNAPSHOT\cpulimitController-1.0-SNAPSHOT.jar
[INFO] Installing Z:\users\doc\GitHub\cpulimitController\pom.xml to C:\Users\何某\.m2\repository\com\haniokasai\cpulimitController\1.0-SNAPSHOT\cpulimitController-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.164 s
[INFO] Finished at: 2018-11-09T01:25:11+09:00
[INFO] Final Memory: 9M/128M
[INFO] ------------------------------------------------------------------------

すると、C:\Users\何某.m2\repository\にpomとかjarが設置される。

使用する方にて

ローカルリポジトリ追加

pom.xml
    <repositories>
        <repository>
            <id>localrepo</id>
            <name>localrepo</name>
            <url>file://${basedir}/libs/</url>
        </repository>
    </repositories>

さらに

pom.xml
        <dependency>
            <groupId>com.haniokasai</groupId>
            <artifactId>cpulimitController</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

と書けばいい。

そして、 ./libs フォルダに この場合だったら、C:\Users\何某.m2\repository\com\haniokasai\cpulimitControllerの中身のjarとpomと_remote.repositories
をおけばいい。

Ref

https://stackoverflow.com/questions/18732175/the-pom-for-project-is-missing-no-dependency-information-available