Setting up Build for your project with Maven and Jenkins

Building your Project with Maven

How to build test jar and include in your war or final jar

  1. Build your jar and test jar for the module.
  2. When building the war, add test jar as dependency which causes the test jar to be included in the war.

Adding Resources to your jar

Simply add following entry to your build

<build>
       <resources>
		<resource>
			<directory>src/main/resources </directory>
			<includes>
				<include>**/*.xml </include>
			</includes>
		</resource>
	</resources>
</build>

 

Copying your dependencies in the jar

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>             
      <id>copy-dependencies</id>
      <phase>compile</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <artifactSet>
          <includes>
        <include>com.example:foo</include>
          </includes>
        </artifactSet>
        <outputDirectory>target/dependencies</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin> 

Build a jar with test classes.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

 


Jenkins Setup

Wiki setting up Jenkins in Ubuntu on

  1. https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
  2. http://emma.sourceforge.net/samples.html

Reference

  1. Apache Maven include/Exclude resources
  2. Oracle Maven Document
  3. A short blog on Maven Project
  4. HTML Tags in W3School
  5. https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
  6. http://emma.sourceforge.net/samples.html