Friday, November 13, 2009

Adding a jar to a local file system maven2 repository using deploy:deploy-file

It seems mvn is extremely picky about the syntax for this. Here's an example on windows that works with both apache-maven-2.0.9 and apache-maven-2.2.1:

C:\temp>mvn deploy:deploy-file -Dfile=gdata-calendar-2.0.jar -Durl=file:C:\m2repo -DgroupId=com.google -DartifactId=gdata-calendar -Dversion=2.0 -Dpackaging=jar

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'deploy'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [deploy:deploy-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [deploy:deploy-file]
Uploading: file:C:\m2repo/com/google/gdata-calendar/2.0/gdata-calendar-2.0.jar
48K uploaded
[INFO] Retrieving previous metadata from remote-repository
[INFO] repository metadata for: 'artifact com.google:gdata-calendar' could not b
e found on repository: remote-repository, so will be created
[INFO] Uploading repository metadata for: 'artifact com.google:gdata-calendar'
[INFO] Uploading project information for gdata-calendar 2.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Nov 13 11:00:03 EST 2009
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------


To simplify, you can use this command:

upload gdata-calendar 2.0 com.google


If you first create this batch script:

call mvn deploy:deploy-file -Dfile=%1-%2.jar -Durl=file:C:\m2repo -DgroupId=%3 -DartifactId=%1 -Dversion=%2 -Dpackaging=jar


If you also want to create a simple maven2 entry, add this to the above script (note the Windows Command Interpreter escape character is "^"):

echo ^<dependency^> >> pom-dependencies.txt
echo ^<groupId^>%3^</groupId^> >> pom-dependencies.txt
echo ^<artifactId^>%1^</artifactId^> >> pom-dependencies.txt
echo ^<version^>%2^</version^> >> pom-dependencies.txt
echo ^</dependency^> >> pom-dependencies.txt


And finally, this batch scrip will upload all the jars in Google's Java API:

call upload gdata-analytics 2.0 com.google
call upload gdata-analytics-meta 2.0 com.google
call upload gdata-appsforyourdomain 1.0 com.google
call upload gdata-appsforyourdomain-meta 1.0 com.google
call upload gdata-base 1.0 com.google
call upload gdata-blogger 2.0 com.google
call upload gdata-blogger-meta 2.0 com.google
call upload gdata-books 1.0 com.google
call upload gdata-books-meta 1.0 com.google
call upload gdata-calendar 2.0 com.google
call upload gdata-calendar-meta 2.0 com.google
call upload gdata-client 1.0 com.google
call upload gdata-client-meta 1.0 com.google
call upload gdata-codesearch 2.0 com.google
call upload gdata-codesearch-meta 2.0 com.google
call upload gdata-contacts 3.0 com.google
call upload gdata-contacts-meta 3.0 com.google
call upload gdata-core 1.0 com.google
call upload gdata-docs 3.0 com.google
call upload gdata-docs-meta 3.0 com.google
call upload gdata-finance 2.0 com.google
call upload gdata-finance-meta 2.0 com.google
call upload gdata-health 2.0 com.google
call upload gdata-health-meta 2.0 com.google
call upload gdata-maps 2.0 com.google
call upload gdata-maps-meta 2.0 com.google
call upload gdata-media 1.0 com.google
call upload gdata-photos 2.0 com.google
call upload gdata-photos-meta 2.0 com.google
call upload gdata-projecthosting 2.0 com.google
call upload gdata-projecthosting-meta 2.0 com.google
call upload gdata-sidewiki 2.0 com.google
call upload gdata-sidewiki-meta 2.0 com.google
call upload gdata-sites 2.0 com.google
call upload gdata-sites-meta 2.0 com.google
call upload gdata-spreadsheet 3.0 com.google
call upload gdata-spreadsheet-meta 3.0 com.google
call upload gdata-webmastertools 2.0 com.google
call upload gdata-webmastertools-meta 2.0 com.google
call upload gdata-youtube 2.0 com.google
call upload gdata-youtube-meta 2.0 com.google


Note you can also use mvn install:install-file as per this blog post.

0 comments:

Stats