1. Set up your Maven repo project on Github.
You need to figure out where you are going to deploy and then host your project's artifacts. Here I have created a new repo on Github, and checked it out at the root of my dev directory.
dhcp123:server htxiong$ git clone git@github.com:htxiong/htxiong-mvn-repo.git
Initialized empty Git repository in ~/dev/htxiong-mvn-repo/.git/
warning: You appear to have cloned an empty repository.
2. Set up separate snapshots and releases directories.
This is not a technical necessity, but its good to maintain a ongoing project by separating snapshots and releases directories.
dhcp123:server htxiong$ cd htxiong-mvn-repo
dhcp123:server htxiong$ mkdir snapshots
dhcp123:server htxiong$ mkdir releases
3. Deploy your project's artifacts to Maven repo.
In your project's pom.xml file, there is a configuration element <distributionManagement> that specifies the repositories to which one's project artifacts should be deployed. If you can not find it in your project's pom.xml, please add the following content into it and just before tag </project>.
<distributionManagement>
<snapshotRepository>
<id>mvn-repo-snapshot</id>
<name>Maven repo example Snapshots</name>
<url>https://github.com/htxiong/htxiong-mvn-repo/raw/master/snapshots</url>
</snapshotRepository>
<repository>
<id>mvn-repo</id>
<name>Maven repo example Releases</name>
<url>https://github.com/htxiong/htxiong-mvn-repo/raw/master/releases</url>
</repository>
</distributionManagement> Now let's build and deploy the project's artifacts by using
altDeploymentRepository
system property.For snapshots:
dhcp123:server htxiong$ mvn -DaltDeploymentRepository=snapshot-repo::default::file:snapshots clean deploy
For releases:
dhcp123:server htxiong$ mvn -DaltDeploymentRepository=repo::default::file:releases clean deploy
And more information about DaltDeploymentRepository can be found at http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html#altDeploymentRepository.
4. Push to Github.
In the first 3 steps, we have built and deployed your project's artifacts in our local maven repo which is just like any other git repo, so changes need to be committed and pushed up in order to be useful.
dhcp123:server htxiong$ git add snapshots/*
dhcp123:server htxiong$ git add releases/*
dhcp123:server htxiong$ git commit -m ''add snapshots and releases"
dhcp123:server htxiong$ git push
5. Use your new Maven repo in other projects.
We have already deployed our project on Github as maven repo and the root of this repo will be at https://github.com/htxiong/htxiong-mvn-repo/raw/master/, then it is time now to use it in other projects by putting the following content into pom.xml.
For snapshots:
<repository>
<id>-htxiong-mvn-repo</id>
<url>https://github.com/htxiong/htxiong-mvn-repo/raw/master/snapshots</url>
</repository>
For releases:
<repository>
<id>-htxiong-mvn-repo</id>
<url>https://github.com/htxiong/htxiong-mvn-repo/raw/master/releases</url>
</repository>
DONE!
No comments:
Post a Comment