by ampatspell
in Code
While mvn install publishes artifact to local ~/.m2/repository there is certainly good rationale to create a remote “company” maven repository (either using cool tools like nexus or with just simple HTTP server) to share built artifacts.
If you’re like me — just starting with Maven, plain old HTTP will be fine and when repository is ready (when mkdir /var/www/repository has done it’s job) then the next question is how to publish artifacts.
There are 2 ways (I’m aware of) to get built artifacts in repository:
maven-release-pluginmaven-deploy-pluginBefore diving in both of them pom.xml needs a tweaks.
Maven needs to know where your repository is. We need to add distributionManagement element:
<distributionManagement> <repository> <id>company-repository</id> <name>company m2 repository</name> <url>scp://deploy@company.server.com/var/www/repository</url> </repository> </distributionManagement>
Example uses scp, few other protocols are supported.
And for maven-release-plugin we also need scm settings in place:
<scm> <connection>scm:hg:ssh://hg@company.server.com/hg/project</connection> <developerConnection>scm:hg:ssh://hg@company.server.com/hg/project</developerConnection> </scm>
Fine, lets deploy a SNAPSHOT release:
mvn clean deploy
This will clean, build and deploy artifact with current version (event if it is not marked as a SNAPSHOT). Note that it will also overwrite existing artifacts in repository if they exist.
The release plugin is a lot smarter. The release process is divided in two steps — prepare and perform. Prepare works something like this (assuming artifactId is “zeeba”):
1.0-SNAPSHOT to 1.0zeeba-1.01.0 to 1.1-SNAPSHOTAfter each of those tasks release:prepare also commits and pushes the change to scm. So after single release:prepare you’ll get 3 change-sets in scm
The perform side of the plugin is cloning repository based on saved release scm tag name in release.properties, rebuilding (goal ‘deploy’) and finally performing the actual release. So if release:perform fails it can be safely retried until it succeeds.
mvn release:prepare mvn release:perform
Note, this plugin requires project to currently have SNAPSHOT version.
|
And I can’t recommend more the Maven: The Definitive Guide. It is really good getting started guide for newcomers to maven. |