- 追加された行はこの色です。
- 削除された行はこの色です。
取り急ぎ、pom.xml
#topicpath
----
#contents
GitHubでMavenのJavaプロジェクトを管理しているケースで、ビルド時に作成したjarをどうやって公開するかについてです。GitHubのReleasesにjarをアップするとかも考えましたが、いっそGitHub上に専用のMavenリポジトリを準備して、そこにjarやpomを一色アップするやり方もよさそうです。
その手順について。
たとえば
https://raw.github.com/masatomix/github-maven-repo-sample/maven-repo/
のようなURLを準備し、そこにリポジトリを構築することを考えます。そうしておけば、そのjarを利用したい側は、自分のpom.xml側で、
<repositories>
<repository>
<id>my-maven-repo</id>
<url>https://raw.github.com/masatomix/github-maven-repo-sample/maven-repo/</url>
</repository>
</repositories>
としてリポジトリを定義して、dependency では
<dependency>
<groupId>nu.mine.kino</groupId>
<artifactId>github-maven-repo-sample</artifactId>
<version>0.0.1</version>
</dependency>
とこんな感じでjarを利用することができるようになります。
**取り急ぎ、pom.xml [#v2d21a7c]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/maven-repo
たとえば
https://raw.github.com/masatomix/github-maven-repo-sample/maven-repo
をリポジトリとするためのサンプルのpom.xml
# mvn clean deployとすることで、上記のURLに、mavenのリポジトリが作成される。
そのrepositoryのjarを参照したいプロジェクトからは、pom.xmlで下記のrepositoryを定義した上で、
<repositories>
<repository>
<id>my-maven-repo</id>
<url>https://raw.github.com/masatomix/maven-repo/maven-repo/</url>
</repository>
</repositories>
で、さらにpom.xmlで、
<dependency>
<groupId>nu.mine.kino</groupId>
<artifactId>github-maven-repo-sample</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>nu.mine.kino</groupId>
<artifactId>github-maven-repo-sample</artifactId>
<version>0.0.1</version>
</dependency>
と書くことができます。
-->
<modelVersion>4.0.0</modelVersion>
<groupId>nu.mine.kino</groupId>
<artifactId>github-maven-repo-sample</artifactId>
<version>0.0.4</version>
<modelVersion>4.0.0</modelVersion>
<groupId>nu.mine.kino</groupId>
<artifactId>github-maven-repo-sample</artifactId>
<version>0.0.4</version>
<!--
distributionManagement の記述。これを書くだけで、
# mvn clean deployで、target/maven-repo 配下に、リポジトリが作成されるようになる
-->
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Temporary Staging Repository</name>
<url>file://${project.build.directory}/repository</url>
</repository>
</distributionManagement>
<!--
distributionManagement の記述。これを書くだけで、
# mvn clean deployで、target/repository 配下に、リポジトリが作成されるようになる
-->
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Temporary Staging Repository</name>
<url>file://${project.build.directory}/repository</url>
</repository>
</distributionManagement>
<properties>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<!--
$ cat ~/.m2/settings.xml
<settings>
<servers>
<server>
..
</server>
<server>
<id>github</id>
<username>YOUR-USERNAME</username>
<password>xxxxxxxxx</password>
</server>
</servers>
</settings>
-->
<github.global.server>github</github.global.server>
</properties>
<properties>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<!--
$ cat ~/.m2/settings.xml
<settings>
<servers>
<server>
..
</server>
<server>
<id>github</id>
<username>YOUR-USERNAME</username>
<password>xxxxxxxxx</password>
</server>
</servers>
</settings>
-->
<github.global.server>github</github.global.server>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/repository</altDeploymentRepository>
</configuration>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.11</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<!-- git commit message -->
<noJekyll>true</noJekyll>
<!-- disable webpage processing -->
<outputDirectory>${project.build.directory}/repository</outputDirectory>
<!-- matches distribution management repository url above -->
<branch>refs/heads/maven-repo</branch>
<!-- remote branch name -->
<includes>
<include>**/*</include>
</includes>
<repositoryName>github-maven-repo-sample</repositoryName><!-- Github上のどのプロジェクトにアップするか。別のプロジェクトも選べる -->
<!-- github repo name -->
<repositoryOwner>YOUR-USERNAME</repositoryOwner>
<!-- github username -->
<merge>true</merge> <!-- 履歴を残す。これがないと、直近バージョンしかrepositoryに残らない -->
</configuration>
<executions>
<!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase -->
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>deploy</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>deploy</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/repository</altDeploymentRepository>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.11</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<!-- git commit message -->
<noJekyll>true</noJekyll>
<!-- disable webpage processing -->
<outputDirectory>${project.build.directory}/repository</outputDirectory>
<!-- matches distribution management repository url above -->
<branch>refs/heads/maven-repo</branch>
<!-- remote branch name -->
<includes>
<include>**/*</include>
</includes>
<repositoryName>github-maven-repo-sample</repositoryName><!-- Github上のどのプロジェクトにアップするか。別のプロジェクトも選べる -->
<!-- github repo name -->
<repositoryOwner>YOUR-USERNAME</repositoryOwner>
<!-- github username -->
<merge>true</merge> <!-- 履歴を残す。これがないと、直近バージョンしかrepositoryに残らない -->
</configuration>
<executions>
<!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase -->
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
** 他のプロジェクトから参照したときエラーになる場合。 [#ye49bde5]
環境によっては、
peer not authenticated
という文言のエラーが発生するっぽい。こんな時はそのプロジェクトのビルド時に、
mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true xxx
などと環境設定を追加してください。
[[java - maven release -> peer not authenticated - Stack Overflow>https://stackoverflow.com/questions/15691985/maven-release-peer-not-authenticated]]
**関連リンク [#b91db73b]
-[[Hosting a Maven repository on github - Stack Overflow>https://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github]]
-[[Github上に私設Mavenリポジトリをつくる - M12i.>http://m12i.hatenablog.com/entry/2015/06/06/135701]]
-https://github.com/masatomix/github-maven-repo-sample
----
この記事は
#vote(おもしろかった,そうでもない)
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}