読者です 読者をやめる 読者になる 読者になる

S3をmavenリポジトリとして使う

まあこのへんみれば楽勝なのですが、日本語のリソースもないみたいなので、とりあえず簡単に。Asakusaも、いまのとこ、S3にリポジトリをつくってます。

いまのところ、springのリポジトリにあるwagonのやつが一番いけてるらしいので、とりあえずそれを使う流れにします。セントラルにあっていいものな気はするけど。


では、一応、元ネタの順序に従ってすすめていきます。出来上がりのプロジェクト群は、これです。


1. 下記をリポジトリにデプロイしたいプロジェクトのpom.xmlに追記します

<build>
	<extensions>
		<extension>
			<groupId>org.springframework.build.aws</groupId>
			<artifactId>org.springframework.build.aws.maven</artifactId>
			<version>3.0.0.RELEASE</version>
		</extension>
	</extensions>
</build>


2. S3のbucketをつくります。


3. 下記をリポジトリにデプロイしたいプロジェクトのpom.xmlに追記します

<distributionManagement>
	<repository>
		<id>marble-repository</id>
		<name>sample s3 repository</name>
		<url>s3://marble-repository/release/</url>
	</repository>
</distributionManagement>


4. このへんでとれるセキュリティ証明証の記述を ~/.m2/settings.xml に追記します。

<server>
	<id>marble-repository</id>
	<username>シークレットキー</username>
	<passphrase>アクセスキー</passphrase>
</server>

なんかmavenのバージョンによっては暗号化がいるとか書いてありますが、僕の環境ではいらないっぽいです。それもどうなのかとかありますが。


5. 対象のプロジェクトをデプロイします。mvn deployしてください。

ログはっておきます。なんかディレクトリがないときは例外を握ってつくってるっぽいですが、ちゃんとデプロイされます。

C:\development\sources\maven-s3deploy-example\sample-parent>mvn deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-parent 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ sample-parent

    • -

[INFO] Installing C:\development\sources\maven-s3deploy-example\sample-parent\po
m.xml to C:\Users\shingo.furuyama.ULDOMAIN\.m2\repository\marblejenka\sample-par
ent\0.0.1-SNAPSHOT\sample-parent-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ sample-parent ---
Downloading: s3://marble-repository/release/marblejenka/sample-parent/0.0.1-SNAP
SHOT/maven-metadata.xml
2011/04/23 20:51:30 org.jets3t.service.impl.rest.httpclient.RestS3Service perfor
mRequest
警告: Error Response: GET '/release%2Fmarblejenka%2Fsample-parent%2F0.0.1-SNAPSH
OT%2Fmaven-metadata.xml' -- ResponseCode: 404, ResponseStatus: Not Found, Reques
t Headers: [Content-Type: , Date: Sat, 23 Apr 2011 11:51:28 GMT, Authorization:
AWS AKIAJRTSER32TATY535Q:RhjSUW3ujLFKtFWzhhHD8XKmrFo=, User-Agent: JetS3t/0.7.1
(Windows 7/6.1; amd64; ja; JVM 1.6.0_23), Host: marble-repository.s3.amazonaws.c
om], Response Headers: [x-amz-request-id: 00CF0EA970358B5C, x-amz-id-2: j1Qk5+YL
AaIG7eE2L1h3BRMY/trm10q7sUPdEQleTkSnnHJOhiYbf3oppL2SE1NR, Content-Type: applicat
ion/xml, Transfer-Encoding: chunked, Date: Sat, 23 Apr 2011 11:51:30 GMT, Server
: AmazonS3]
2011/04/23 20:51:30 org.jets3t.service.impl.rest.httpclient.RestS3Service perfor
mRequest
致命的: Request Failed.
org.jets3t.service.S3ServiceException: S3 Error Message. GET '/release%2Fmarblej
enka%2Fsample-parent%2F0.0.1-SNAPSHOT%2Fmaven-metadata.xml' on Host 'marble-repo
sitory.s3.amazonaws.com' @ 'Sat, 23 Apr 2011 11:51:30 GMT' -- ResponseCode: 404,
ResponseStatus: Not Found, XML Error Message:

  • 8"?>NoSuchKeyThe specified key does not exist.

ssage>release/marblejenka/sample-parent/0.0.1-SNAPSHOT/maven-metadata.xml00CF0EA970358B5Cj1Qk5+YLAaIG7eE2L1h3BRMY/trm1
0q7sUPdEQleTkSnnHJOhiYbf3oppL2SE1NR

at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(
RestS3Service.java:441)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestGet(
RestS3Service.java:876)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(R
estS3Service.java:1712)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(R
estS3Service.java:1655)
at org.jets3t.service.S3Service.getObject(S3Service.java:2215)
at org.jets3t.service.S3Service.getObject(S3Service.java:1424)
at org.springframework.aws.maven.SimpleStorageServiceWagon.getResource(S
impleStorageServiceWagon.java:93)
at org.springframework.aws.maven.AbstractWagon.get(AbstractWagon.java:18
4)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.
run(WagonRepositoryConnector.java:608)
at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(Run
nableErrorForwarder.java:64)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:662)
Uploading: s3://marble-repository/release/marblejenka/sample-parent/0.0.1-SNAPSH
OT/sample-parent-0.0.1-20110423.115130-1.pom
Uploaded: s3://marble-repository/release/marblejenka/sample-parent/0.0.1-SNAPSHO
T/sample-parent-0.0.1-20110423.115130-1.pom (2 KB at 0.8 KB/sec)
Downloading: s3://marble-repository/release/marblejenka/sample-parent/maven-meta
data.xml
2011/04/23 20:51:31 org.jets3t.service.impl.rest.httpclient.RestS3Service perfor
mRequest
警告: Error Response: GET '/release%2Fmarblejenka%2Fsample-parent%2Fmaven-metada
ta.xml' -- ResponseCode: 404, ResponseStatus: Not Found, Request Headers: [Conte
nt-Type: , Date: Sat, 23 Apr 2011 11:51:31 GMT, Authorization: AWS AKIAJRTSER32T
ATY535Q:rIib2fXRBHd+hM9/SwB3dLqUWlM=, User-Agent: JetS3t/0.7.1 (Windows 7/6.1; a
md64; ja; JVM 1.6.0_23), Host: marble-repository.s3.amazonaws.com], Response Hea
ders: [x-amz-request-id: 244501401B5538EE, x-amz-id-2: nl6/pgsNFaytt2sKiLRDw0vlf
XdTlloFbFN7l4VcKf+5EyfRda2Ijq3qWknVBIZR, Content-Type: application/xml, Transfer

  • Encoding: chunked, Date: Sat, 23 Apr 2011 11:51:31 GMT, Server: AmazonS3]

2011/04/23 20:51:31 org.jets3t.service.impl.rest.httpclient.RestS3Service perfor
mRequest
致命的: Request Failed.
org.jets3t.service.S3ServiceException: S3 Error Message. GET '/release%2Fmarblej
enka%2Fsample-parent%2Fmaven-metadata.xml' on Host 'marble-repository.s3.amazona
ws.com' @ 'Sat, 23 Apr 2011 11:51:31 GMT' -- ResponseCode: 404, ResponseStatus:
Not Found, XML Error Message: NoSuchKeyThe specified key does not exist.releas
e/marblejenka/sample-parent/maven-metadata.xml
244501401B5538EE<
/RequestId>nl6/pgsNFaytt2sKiLRDw0vlfXdTlloFbFN7l4VcKf+5EyfRda2Ijq3qWknVB
IZR

at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(
RestS3Service.java:441)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestGet(
RestS3Service.java:876)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(R
estS3Service.java:1712)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(R
estS3Service.java:1655)
at org.jets3t.service.S3Service.getObject(S3Service.java:2215)
at org.jets3t.service.S3Service.getObject(S3Service.java:1424)
at org.springframework.aws.maven.SimpleStorageServiceWagon.getResource(S
impleStorageServiceWagon.java:93)
at org.springframework.aws.maven.AbstractWagon.get(AbstractWagon.java:18
4)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.
run(WagonRepositoryConnector.java:608)
at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(Run
nableErrorForwarder.java:64)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:662)
Uploading: s3://marble-repository/release/marblejenka/sample-parent/0.0.1-SNAPSH
OT/maven-metadata.xml
Uploaded: s3://marble-repository/release/marblejenka/sample-parent/0.0.1-SNAPSHO
T/maven-metadata.xml (601 B at 0.5 KB/sec)
Uploading: s3://marble-repository/release/marblejenka/sample-parent/maven-metada
ta.xml
Uploaded: s3://marble-repository/release/marblejenka/sample-parent/maven-metadat
a.xml (284 B at 0.2 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.777s
[INFO] Finished at: Sat Apr 23 20:51:34 JST 2011
[INFO] Final Memory: 4M/57M
[INFO] ------------------------------------------------------------------------

なにげにアクセスキーがでてますが、まあ気にしません。無効化したし。


6. クライアントからは、下記のような記述でS3のリポジトリから依存関係を解決してくれます。

<repositories>
	<repository>
		<id>marble-repository</id>
		<name>sample s3 repository</name>
		<url>https://marble-repository.s3.amazonaws.com/release</url>
	</repository>
</repositories>

<dependencies>
	<dependency>
		<groupId>marblejenka</groupId>
		<artifactId>sample-child</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</dependency>
</dependencies>

ということで、デプロイができました。management consoleからみると、

こんな感じです。お手軽ですね。


S3だとおかねかかるからペンギンにデプロイできたりするといいかもなあとか。google codeでもなんでもいいんだけど。