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 †<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"> <!-- 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> と書くことができます。 --> <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/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> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.2</version> <scope>provided</scope> </dependency> </dependencies> <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> 他のプロジェクトから参照したときエラーになる場合。 †環境によっては、 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 関連リンク †
この記事は 現在のアクセス:2013 |