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
- Version of the build
- 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
- plugin - values will be used to parse the online maven repository & download matching libraries
- sourceDirectory
- dependencies
- dependency
- groupId
- artifactId
- version
- dependency
- modelVersion
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
- Maven > User Settings
- 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 > Lifecycle Mapping
-
-
- 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....
- SeleniumFramework <-- this is the project name
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:
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <id>bin</id>
- <formats>
- <format>tar.gz</format>
- <format>tar.bz2</format>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>README*</include>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}/site</directory>
- <outputDirectory>docs</outputDirectory>
- </fileSet>
- </fileSets>
- </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:
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <!-- TODO: a jarjar format would be better -->
- <id>jar-with-dependencies</id>
- <formats>
- <format>jar</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <dependencySets>
- <dependencySet>
- <outputDirectory>/</outputDirectory>
- <useProjectArtifact>true</useProjectArtifact>
- <unpack>true</unpack>
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
- </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:
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <id>src</id>
- <formats>
- <format>tar.gz</format>
- <format>tar.bz2</format>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}</directory>
- <includes>
- <include>README*</include>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- <include>pom.xml</include>
- </includes>
- <useDefaultExcludes>true</useDefaultExcludes>
- </fileSet>
- <fileSet>
- <directory>${project.basedir}/src</directory>
- <useDefaultExcludes>true</useDefaultExcludes>
- </fileSet>
- </fileSets>
- </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:
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <id>project</id>
- <formats>
- <format>tar.gz</format>
- <format>tar.bz2</format>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}</directory>
- <outputDirectory>/</outputDirectory>
- <useDefaultExcludes>true</useDefaultExcludes>
- <excludes>
- <exclude>**/*.log</exclude>
- <exclude>**/${project.build.directory}/**</exclude>
- </excludes>
- </fileSet>
- </fileSets>
- </assembly>
- Log in to post comments