Java POM: 02-Maven Config

 

POM Anatomy

  • Project
    • modelVersion
      • Version of POM Schema
    • groupId
      • ProjectName
    • artifactId
      • <ProjectName> - use the project name if the project is the TOP level of a project that has other projects embedded as subfolders
      • <SubProjectName> if project is a dependency of a larger project
    • version
      • Version of the build
        • usually starting with 0.0.1-SNAPSHOT
        • then increments after each official release
    • properties
      • jre.level - used to set required JRE version
      • jdk.level - used to set the required JDK version
      • junit.jupiter.version(optional)
        • used in the POM file to make updating versions easier.
        • implement using ${junit.jupiter.version}
      • junit.platform.version(optional)
        • used in the POM file to make updating versions easier.
        • implement using ${junit.platform.version}
    • build
      • sourceDirectory
        • src
      • pluginManagement
        • plugins
      • plugins - used to specify build plugins for [compiling], [test], assembling the JAR & JAR+dependencies
        • plugin - values will be used to parse the online maven repository & download matching libraries
          • groupId
          • artifactId
          • version
          • configuration
            • source
            • target
    • dependencies
      • dependency
        • groupId
        • artifactId
        • version

 

 

POM Complete

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>SeleniumFramework</groupId>
    <artifactId>SeleniumFramework</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <jre.level>1.8</jre.level>
        <jdk.level>1.8</jdk.level>
        <junit.jupiter.version>5.2.0</junit.jupiter.version>
        <junit.platform.version>1.2.0</junit.platform.version>
    </properties>
    <build>
        <sourceDirectory>src</sourceDirectory>

        <pluginManagement>
            <plugins>
                <!-- plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.14.1</version> <configuration> <forkCount>0</forkCount> <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> <testFailureIgnore>true</testFailureIgnore>
                    </configuration> </plugin -->
            </plugins>
        </pluginManagement>

        <plugins>
            <!-- Compiler plug-in -->
            <!-- Below plug-in is used to execute tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <forkCount>0</forkCount>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>true</testFailureIgnore>
                    <properties>
                        <property>
                            <name>testnames</name>
                            <value>"Simple Test</value>
                        </property>
                    </properties>
                </configuration>
            </plugin>
            <!-- Junit5
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>${junit.platform.version}</version>
                    </dependency>
                </dependencies>
            </plugin>  -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.stack.JarCreation.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <archive>
                                <manifest>
                                    <mainClass>com.stack.JarCreation.Main</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <!-- Include the following dependencies -->
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.9</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
        <!-- dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
            <version>3.8.1</version> <scope>test</scope> </dependency -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

 

Clean

 

Install

 

Build

 

Compile

 

Test

 


Run Configurations

  • Project > Preferences
    • Maven > User Settings
      • Local Repo : C:\Users\<user>\.m2\repository
  • Run As > Run Configurations...
  • Project > Properties
    • Maven > Lifecycle Mapping
      • clean:clean
      • resources
      • compiler
      • resources:testResources
      • compiler:testCompile
      • surefire:tet
      • jar:ar
      • assembly:attached
      • install:install
      • deploy:deploy
      • site:site
      •  
  • Maven Build
    • SeleniumFramework <-- this is the project name
      • Base directory: ${project_loc:SeleniumFramework}
      • Goals: compile
      • Maven Runtime: EMBEDDED ( 3.3.9/1.8.2.20171007-0216)
        • Configure....

 

 

 

 

Lifecycle Mapping

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
  <lifecycleMappings>
    <lifecycleMapping>
      <pluginExecutions>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <versionRange>2.5</versionRange>
            <goals>
              <goal>clean</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <versionRange>[2.4,)</versionRange>
            <goals>
              <goal>testResources</goal>
              <goal>copy-resources</goal>
              <goal>resources</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <execute>
              <runOnIncremental>true</runOnIncremental>
            </execute>
          </action>
          <comment>source: default</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
            <parameters>
              <compilerId>javac</compilerId>
            </parameters>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.eclipse.m2e.jdt.javaConfigurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905),extension(org.eclipse.m2e.wtp.jpa_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.java.unsupportedDependencyTypeConfigurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905),extension(org.eclipse.m2e.wtp.jpa_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.eclipse.m2e.wtp.jpa.configurator.jdt</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905),extension(org.eclipse.m2e.wtp.jpa_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.utility.configurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905),extension(org.eclipse.m2e.wtp.jpa_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.webfragment.configurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905),extension(org.eclipse.m2e.wtp.jpa_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <versionRange>[2.4,)</versionRange>
            <goals>
              <goal>testResources</goal>
              <goal>copy-resources</goal>
              <goal>resources</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <execute>
              <runOnIncremental>true</runOnIncremental>
            </execute>
          </action>
          <comment>source: default</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
            <parameters>
              <compilerId>javac</compilerId>
            </parameters>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.eclipse.m2e.jdt.javaConfigurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.java.unsupportedDependencyTypeConfigurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.utility.configurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>testCompile</goal>
              <goal>compile</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.maven.ide.eclipse.configuration.wtp.webfragment.configurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.eclipse.m2e.jdt_1.8.2.20171007-0217),extension(org.eclipse.m2e.wtp_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <versionRange>2.18.1</versionRange>
            <goals>
              <goal>test</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <versionRange>[2.0,)</versionRange>
            <goals>
              <goal>jar</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.sonatype.m2e.mavenarchiver.jararchiverconfigurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.sonatype.m2e.mavenarchiver_0.17.2.201606141937-signed-20160830073346),extension(org.eclipse.m2e.wtp.jaxrs_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <versionRange>[1.0,)</versionRange>
            <goals>
              <goal>jar</goal>
            </goals>
          </pluginExecutionFilter>
          <action>
            <configurator>
              <id>org.eclipse.m2e.wtp.jaxrs.configurator</id>
            </configurator>
          </action>
          <comment>source: extension(org.sonatype.m2e.mavenarchiver_0.17.2.201606141937-signed-20160830073346),extension(org.eclipse.m2e.wtp.jaxrs_1.3.3.20170823-1905)</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <versionRange>2.2-beta-5</versionRange>
            <goals>
              <goal>attached</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <versionRange>2.4</versionRange>
            <goals>
              <goal>install</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <versionRange>2.7</versionRange>
            <goals>
              <goal>deploy</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
        <pluginExecution>
          <pluginExecutionFilter>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <versionRange>3.3</versionRange>
            <goals>
              <goal>site</goal>
            </goals>
          </pluginExecutionFilter>
          <ignore />
          <comment>source: uninteresting</comment>
        </pluginExecution>
      </pluginExecutions>
    </lifecycleMapping>
  </lifecycleMappings>
</lifecycleMappingMetadata>


 

Maven Assembly Plugin

https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html

Pre-defined Descriptor Files

There are four predefined descriptor formats available for reuse, packaged within the Assembly Plugin. Their descriptorIds are:

bin

Use bin as the descriptorRef of your assembly-plugin configuration in order to create a binary distribution archive of your project. This built-in descriptor produces an assembly with the classifier bin in three archive formats: tar.gz, tar.bz2, and zip.

The assembled archive contains the binary JAR produced by running mvn package plus any README, LICENSE, and NOTICE files available in the project root directory.

Below is the bin descriptor format:


 
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <id>bin</id>
  5. <formats>
  6. <format>tar.gz</format>
  7. <format>tar.bz2</format>
  8. <format>zip</format>
  9. </formats>
  10. <fileSets>
  11. <fileSet>
  12. <directory>${project.basedir}</directory>
  13. <outputDirectory>/</outputDirectory>
  14. <includes>
  15. <include>README*</include>
  16. <include>LICENSE*</include>
  17. <include>NOTICE*</include>
  18. </includes>
  19. </fileSet>
  20. <fileSet>
  21. <directory>${project.build.directory}</directory>
  22. <outputDirectory>/</outputDirectory>
  23. <includes>
  24. <include>*.jar</include>
  25. </includes>
  26. </fileSet>
  27. <fileSet>
  28. <directory>${project.build.directory}/site</directory>
  29. <outputDirectory>docs</outputDirectory>
  30. </fileSet>
  31. </fileSets>
  32. </assembly>

jar-with-dependencies

Use jar-with-dependencies as the descriptorRef of your assembly-plugin configuration in order to create a JAR which contains the binary output of your project, along its the unpacked dependencies. This built-in descriptor produces an assembly with the classifier jar-with-dependencies using the JAR archive format.

Note that jar-with-dependencies provides only basic support for uber-jars. For more control, use the Maven Shade Plugin.

Below is the jar-with-dependencies descriptor format:


 
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <!-- TODO: a jarjar format would be better -->
  5. <id>jar-with-dependencies</id>
  6. <formats>
  7. <format>jar</format>
  8. </formats>
  9. <includeBaseDirectory>false</includeBaseDirectory>
  10. <dependencySets>
  11. <dependencySet>
  12. <outputDirectory>/</outputDirectory>
  13. <useProjectArtifact>true</useProjectArtifact>
  14. <unpack>true</unpack>
  15. <scope>runtime</scope>
  16. </dependencySet>
  17. </dependencySets>
  18. </assembly>

src

Use src as the descriptorRef in your assembly-plugin configuration to create source archives for your project. The archive will contain the contents of your project's /src directory structure, for reference by your users. The src descriptorId produces an assembly archive with the classifier src in three formats: tar.gz, tar.bz2, and zip.

Below is the src descriptor format:


 
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <id>src</id>
  5. <formats>
  6. <format>tar.gz</format>
  7. <format>tar.bz2</format>
  8. <format>zip</format>
  9. </formats>
  10. <fileSets>
  11. <fileSet>
  12. <directory>${project.basedir}</directory>
  13. <includes>
  14. <include>README*</include>
  15. <include>LICENSE*</include>
  16. <include>NOTICE*</include>
  17. <include>pom.xml</include>
  18. </includes>
  19. <useDefaultExcludes>true</useDefaultExcludes>
  20. </fileSet>
  21. <fileSet>
  22. <directory>${project.basedir}/src</directory>
  23. <useDefaultExcludes>true</useDefaultExcludes>
  24. </fileSet>
  25. </fileSets>
  26. </assembly>

project

Using the project <descriptorRef> in your Assembly Plugin configuration will produce an assembly containing your entire project, minus any build output that lands in the /target directory. The resulting assembly should allow your users to build your project using Maven, Ant, or whatever build system you have configured in your project's normal SCM working directory. It produces assemblies with the classifier project in three archive formats: tar.gz, tar.bz2, and zip.

The following is the assembly descriptor for the project descriptorRef:


 
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <id>project</id>
  5. <formats>
  6. <format>tar.gz</format>
  7. <format>tar.bz2</format>
  8. <format>zip</format>
  9. </formats>
  10. <fileSets>
  11. <fileSet>
  12. <directory>${project.basedir}</directory>
  13. <outputDirectory>/</outputDirectory>
  14. <useDefaultExcludes>true</useDefaultExcludes>
  15. <excludes>
  16. <exclude>**/*.log</exclude>
  17. <exclude>**/${project.build.directory}/**</exclude>
  18. </excludes>
  19. </fileSet>
  20. </fileSets>
  21. </assembly>

 

Tags