Thursday, November 3, 2016

Maven Snippets

I find maven documentation cryptic to read and hard to understand, even after years of development this aspect of Maven still remains same to me, most of the time i copy snippets from older projects to get things done, Below you can find some common snippets you might need to use time to time in your projects.


1. Deploying Arbitrary Artifact to Nexus

You need to have configured username and password of your nexus server in your settings.xml file for this snippet to work, it uploads the zip artifact to nexus repository.

settings.xml (located in .m2 directory)

<servers>
    <server>
       <id>nexus</id>
       <username>username</username>
       <password>pass</password>
    </server>

  </servers>

Pom.xml

<!-- Deploy File -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <artifactId>${project.artifactId}</artifactId>
                <groupId>${project.groupId}</groupId>
                <version>${project.version}</version>
                <packaging>zip</packaging>
                <file>target/application-1.0-SNAPSHOT.zip</file>
                <repositoryId>nexus</repositoryId>
                <url>http://xxx.yyy.zz.tt:8081/nexus/content/repositories/snapshots/</url>
            </configuration>
            <goals>
                <goal>deploy-file</goal>
            </goals>
        </execution>
    </executions>
</plugin>