Maven Interview Questions Maven Interview Questions – 150 RealTime Questions
A build tool takes care of everything for building a process of application/software. Main aspects
(i) Generates source code (if auto-generated code is used),
(ii) Generates documentation from source code
(iii) Compiles source code,
(iv) Packages compiled code into JAR of ZIP file
(v) Install the packaged code in local repository, server repository, or central repository
Some of build tools: ANT, MAVEN(Java), MS Build(c++, .NET), Pybuild(python)
Why Maven:
Prerequisites for maven installation:
OS | Supports all major |
RAM | No minimum requirement |
Storage/Disk space | Approximately expect at least 500MB. |
RunTime Environments | Maven 3.9+ requires JDK 8 or above to execute. |
Installation files(offline) or use internet to download | Java SDK, Maven binary file |
Windows/OS with usage privilege | Administrator access/ROOT Privilege |
We can install maven on Windows by using following steps :
Full/Deatailed Article : https://sagarfive.in/maven/installing-maven-on-windows/
It’s clever question, industry never uses latest Maven, Java versions on on Prod, Dev, QA Servers, so better to focus very much on this question
One Variant of use case for a project:
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 10.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: ISO-8859-1
OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"
* If get question like, Why you used open-jdk instead of jdk, then aswer it developement team desicion, so we implemented.
* Might be dev team what to use open-jdk beacuase it is open-source,
* Most of the versions works properly, but might be dependecy specific issue/need with that version of jdk
By running the maven version command on terminal, we can find the version of maven, which is
mvn –version (or)
mvn -v
Terminal Responce :
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 10.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: ISO-8859-1
OS name: “linux”, version: “4.15.0-36-generic”, arch: “amd64”, family: “unix”
mvn [plugin-name]:[goal-name] |
mvn compiler:compile |
Maven Plugin Types :
It is a complete project management tool.
Maven Take care of these
Maven is a build tool along with project management, These are the similar build tools
MAVEN | ANT | |
1 | It is mainly a project management tool. Included build, documentation, reporting | It is mainly a build tool. |
2 | Maven plugins are reusable. | ANT scripts are not reusable |
3 | Maven has a life cycle | ANT has No life cycle |
4 | Maven is declarative everything you define in the pom.xml file. | Ant is procedural, you need to provide information about what to do and when to do through code. You need to provide order. |
5 | Maven has a convention to place source code, compiled code etc. So we don’t need to provide information about the project structure in the pom.xml file. | Ant doesn’t have formal conventions, so we need to provide information of the project structure in the build.xml file. |
mvn archetype:generate |
mvn archetype:generate |
Run the command in cmd(i have installed on c drive , so I opened cmd as run as administrator)
mvn archetype:generate |
C:\MVN>mvn archetype:generate -DarchetypeArtifactId = maven-archetype-quickstart
We can some more information related to project like this
C:\MVN>mvn archetype:generate -DgroupId = com.companyname.bank -DartifactId = consumerBanking -DarchetypeArtifactId = maven-archetype-quickstart
Run the command in cmd to create maven project in your pc
(i have installed on c drive , so I opened cmd as run as administrator)
mvn archetype:generate |
We can work offline in maven, but we need to follow some step
mvn package
” command in Maven?mvn package -DskipTests
“.
The structure of maven project once generated using archetype command(structure varies with the type/variant of archetype)
This is the common/sample project directory structure:
Archetecture:
<project>
<modelVersion/>
<parent/>
<groupId/>
<artifactId/>
<version/>
<packaging/>
<properties/>
<dependencyManagement/>
<dependencies/>
<build/>
<reporting/>
<profiles/>
</project>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<executions>
<execution>
<id>testngtest</id>
<phase>test</phase>
</execution>
</executions>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testngxml.location}/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<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 :
Artifactid:
Version :
<properties> |
<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> </plugins> </pluginManagement> </build> |
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.pre-site</id> <phase>pre-site</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>pre-site phase</echo> </tasks> </configuration> </plugin> |
mvn [plugin-name]:[goal-name] |
mvn compiler:compile |
Maven Plugin Types :
1 | Build plugins | They execute during the build process and should be configured in the <build/> element of pom.xml.Part of Build life cycle |
2 | Reporting plugins | They execute during the site generation process and they should be configured in the <reporting/> element of the pom.xml.Part of Site life cycle |
More info : https://sagarfive.in/maven/plugins/
Example of plugin section in pom.xml :
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.pre-site</id> <phase>pre-site</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>pre-site phase</echo> </tasks> </configuration> </plugin> |
You we can view Super POM(Effective POM) using the command line (first you have to move in your project root folder where pom.xml file exist then type mvn help:effective-pom and press Enter as below
POM vs Super(effective) POM:
Example :
<plugins>
<plugin>
<!-- This declaration makes sure children get plugin in their lifecycle -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Configuration won't be propagated to children -->
<inherited>false</inherited>
<executions>
<execution>
<!--This matches and thus overrides execution defined above -->
<id>checkstyle</id>
<!-- Unbind from lifecycle for this POM -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
Dependecies Types:
pom.xml
file in the <dependencies> section.pom.xml
file. These dependencies are then considered transitive dependencies to the primary project. When Maven pulls a direct dependency, it also pulls its transitive dependencies.<project>
…
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
…
</project>
~/.m2/repository
C:\Users\{your-username}\.m2\repository
By default, Maven local repository is defaulted to ${user.home}/.m2/repository
folder :
<settings>
<!– localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
–>
<localRepository>D:/maven_repo</localRepository>
</settings>
Transitive dependencies: A project included as a dependency in a larger project can declare its own dependencies in a pom.xml
file. These dependencies are then considered transitive dependencies to the primary project. When Maven pulls a direct dependency, it also pulls its transitive dependencies.
Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath.
There are 6 scopes:
compile
, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided
because the web container provides those classes. A dependency with this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive.provided
except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.pom
in the <dependencyManagement>
section. It indicates the dependency is to be replaced with the effective list of dependencies in the specified POM’s <dependencyManagement>
section. Since they are replaced, dependencies with a scope of import
do not actually participate in limiting the transitivity of a dependency.Maven
external dependencies are described in the pom xml
file just like other dependencies
. The parameters required to define the external dependencies
are groupid
, artifactId
, scope set to system and system path as per the project location (relative path).Maven Plugin | Maven Dependency |
---|---|
Plugins are software components that extend the functionality of another software application. | Dependencies are external libraries or modules used to build and run a software project. |
Handling Plugin is usually difficult | Managing a dependency is comparatively easy. |
Used to create jar files and compile code. | Reproducible builds are created and maintained |
<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> </plugins> </pluginManagement> </build> |
Plugins are two types :
1 | Build plugins They execute during the build process and should be configured in the <build/> element of pom.xml. |
2 | Reporting plugins They execute during the site generation process and they should be configured in the <reporting/> element of the pom.xml. |
Types of Build Profile :
Build profiles are majorly of three types.
Type | Where it is defined |
---|---|
Per Project | Defined in the project POM file, pom.xml |
Per User | Defined in Maven settings xml file (%USER_HOME%/.m2/settings.xml) |
Global | Defined in Maven global settings xml file (%M2_HOME%/conf/settings.xml) |
For more : visit
<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>com.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Using env.test.properties</echo>
<copy file="src/main/resources/env.test.properties"
tofile="${project.build.outputDirectory}/env.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
**Run the maven test using test profile
mvn test -Ptest
A Maven Build Profile can be activated in various ways.
Open Maven settings.xml file available in %USER_HOME%/.m2 directory where %USER_HOME% represents the user home directory. If settings.xml file is not there, then create a new one.
<settings 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/settings-1.0.0.xsd”>
<mirrors>
<mirror>
<id>maven.dev.snaponglobal.com</id>
<name>Internal Artifactory Maven repository</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<activeProfiles>
<activeProfile>test</activeProfile>
</activeProfiles>
</settings>
Build profiles are majorly of three types.
Type | Where it is defined |
---|---|
Per Project | Defined in the project POM file, pom.xml |
Per User | Defined in Maven settings xml file (%USER_HOME%/.m2/settings.xml) |
Global | Defined in Maven global settings xml file (%M2_HOME%/conf/settings.xml) |
mvn [plugin-name]:[goal-name] |
mvn compiler:compile |
Maven Plugin Types :
1 | Build plugins | They execute during the build process and should be configured in the <build/> element of pom.xml.Part of Build life cycle |
2 | Reporting plugins | They execute during the site generation process and they should be configured in the <reporting/> element of the pom.xml.Part of Site life cycle |
Some of plugins :
1 | clean | Cleans up the target after the build. Deletes the target directory and artifact |
2 | compiler | Compiles Java source files. |
3 | surefire | Runs the JUnit unit tests. Creates the test reports. |
4 | jar | Build artifact with jar format for the project |
5 | war | Build artifact with war format for the project |
6 | antrun | Runs a set of ant tasks from any phase mentioned of the build. |
7 | javadoc | Generates Javadoc for the project. |
More about : https://sagarfive.in/maven/plugins/
The compiler plugin is used to compile the source code of a Maven project. This plugin has two goals, which are already bound to specific phases of the default lifecycle:
Here’s the compiler plugin in the POM:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
...
</configuration>
</plugin>
Maven Plugin | Maven Dependency |
---|---|
Plugins are software components that extend the functionality of another software application. | Dependencies are external libraries or modules used to build and run a software project. |
Handling Plugin is usually difficult | Managing a dependency is comparatively easy. |
Used to create jar files and compile code. | Reproducible builds are created and maintained |
Maven provides a settings file, settings.xml, which allows us to specify which local and remote repositories it will use. We can also use it to store settings that we don’t want in our source code, such as credentials.
In this tutorial, we’ll learn how to use the settings.xml. We’ll look at proxies, mirroring, and profiles. We’ll also discuss how to determine the current settings that apply to our project.
Configurations :
The settings.xml file configures a Maven installation. It’s similar to a pom.xml file but is defined globally or per user.
Let’s explore the elements we can configure in the settings.xml file. The main settings element of the settings.xml file can contain nine possible predefined child elements:
More : https://sagarfive.in/maven/maven-settings-xml/
We can find the location : mvn help:effective-settings
The settings.xml file configures a Maven installation. It’s similar to a pom.xml file but is defined globally or per user.
Let’s explore the elements we can configure in the settings.xml file. The main settings element of the settings.xml file can contain nine possible predefined child elements:
<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd”> <localRepository/> <interactiveMode/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <profiles/> <activeProfiles/> </settings> |
Local Repository:
Once we have installed Maven, by default, Maven’s local repository is configured to be ‘${user.home}/.m2/repository‘.
In different operating systems, these paths are resolved to –
Changing the local repository:
<!– localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository –>
<localRepository>E:/devsetup/M2</localRepository>
…
…
</settings>
Maven also allows us to override the location of the global and user settings via the command line:
$ mvn clean --settings c:\user\user-settings.xml --global-settings c:\user\global-settings.xml
<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd”>
<mirrors>
<mirror>
<id>aws-codeartifact-repository</id>
<name>AWS CodeArtifact Repo</name>
<url>https://aws.amazon.com/repo/maven2/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
<settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd”>
<profiles>
<profile>
<id>adobe-public</id>
<repositories>
<repository>
<id>adobe-public-releases</id>
<name>Adobe Public Repository</name>
<url>https://repo.adobe.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>adobe-public</id>
<pluginRepositories>
<pluginRepository>
<id>adobe-public-releases</id>
<name>Adobe Public Repository</name>
<url>https://repo.adobe.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>baeldung-test</id>
<properties>
<user.project.folder>${user.home}/baeldung-tutorials</user.project.folder>
</properties>
</profile>
<profile>
<id>baeldung-test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.8</jdk>
<os>
<name>Windows 10</name>
<family>Windows</family>
<arch>amd64</arch>
<version>10.0</version>
</os>
<property>
<name>mavenVersion</name>
<value>3.0.7</value>
</property>
<file>
<exists>${basedir}/activation-file.properties</exists>
<missing>${basedir}/deactivation-file.properties</missing>
</file>
</activation>
</profile>
</profiles>
<activeProfiles>
<activeProfile>baeldung-test</activeProfile>
<activeProfile>adobe-public</activeProfile>
</activeProfiles>
</settings>
Servers :
Maven can have two settings files working at a time:
Both files are optional. If both files are present, the values in the user home settings file override the values from the global settings file.
Maven repository is a directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily. or
A maven repository is a directory of packaged JAR files with a pom.xml file. Maven searches for dependencies in the repositories.
Maven repositories are of three types
(i) Local Repository
(ii) Central Repository
(iii) Remote Repository
Maven repositories are of three types
(i) Local Repository :
<settings xmlns = “http://maven.apache.org/SETTINGS/1.0.0” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation = “http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd”> <localRepository>C:/MyLocalRepository</localRepository></settings> |
(ii) Central Repository :
(iii) Remote Repository :
<repositories> <repository> <id>companyname.lib1</id> <url>http://download.companyname.org/maven2/lib1</url> </repository> </repositories> |
<!– https://mvnrepository.com/artifact/org.jboss.spec.javax.servlet/jboss-servlet-api_3.0_spec –><dependency> <groupId>org.jboss.spec.javax.servlet</groupId> <artifactId>jboss-servlet-api_3.0_spec</artifactId> <version>1.0.2.Final</version> <scope>provided</scope> </dependency> |
Local Repository :
<settings xmlns = “http://maven.apache.org/SETTINGS/1.0.0” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation = “http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd”> <localRepository>C:/MyLocalRepository</localRepository></settings> |
<repositories> <repository> <id>companyname.lib1</id> <url>http://download.companyname.org/maven2/lib1</url> </repository> </repositories> |
<!– https://mvnrepository.com/artifact/org.jboss.spec.javax.servlet/jboss-servlet-api_3.0_spec –><dependency> <groupId>org.jboss.spec.javax.servlet</groupId> <artifactId>jboss-servlet-api_3.0_spec</artifactId> <version>1.0.2.Final</version> <scope>provided</scope> </dependency> |
Maven Dependency Search Sequence :
When we execute Maven build commands, Maven starts looking for dependency libraries in the following sequence
1 | Local Repository | Search dependency in local repository, if not found, move to step 2 else perform the further processing. |
2 | Central repository | Search dependency in central repository, if not found and remote repository/repositories is/are mentioned then move to step 4. Else it is downloaded to the local repository for future reference. |
3 | Remote repository | If a remote repository has not been mentioned, Maven simply stops the processing and throws an error (Unable to find dependency). Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference.Otherwise, Maven stops processing and throws error (Unable to find dependency). |
About the stages:
(i) Default or build Life cycle :
(ii) Clean Life cycle :
(iii) Site Life cycle :
To add a local JAR file to a Maven project, you can use the maven-install-plugin
. Here’s how you can do it:
Place the JAR file in a directory that is accessible to your Maven project.
Add the following build
block to your pom.xml
file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>install-local-jar</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>/path/to/local/jar/file.jar</file>
<groupId>com.example</groupId>
<artifactId>local-jar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Replace /path/to/local/jar/file.jar
with the path to your JAR file.
Replace com.example
with the desired group ID for the JAR file.
Replace local-jar
with the desired artifact ID for the JAR file.
Replace 1.0
with the desired version for the JAR file.
Run the following command to install the JAR file:
mvn install
This will install the JAR file to your local Maven repository, and you can then include it in your project by adding it as a dependency in your pom.xml
file:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>local-jar</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Mostly Used Default or Buid Phases/stages :
Sl. | Stage/Command | Information |
1 | validate | This step validates if the project structure is correct. For example – It checks if all the dependencies have been downloaded and are available in the local repository. |
2 | compile | It compiles the source code, converts the .java files to .class, and stores the classes in the target/classes folder. |
3 | test-compile | Compile the source code in the test destination directory |
4 | test | It runs unit tests for the project. |
5 | package | This step packages the compiled code in a distributable format like JAR or WAR. |
6 | integration-test | It runs the integration tests for the project. |
7 | verify | This step runs checks to verify that the project is valid and meets the quality standards. |
8 | install | This step installs the packaged code to the local Maven repository. |
9 | deploy | It copies the packaged code to the remote repository for sharing it with other developers. |
Sl. | Stage/Command | Information |
1 | validate | This step validates if the project structure is correct. For example – It checks if all the dependencies have been downloaded and are available in the local repository. |
2 | compile | It compiles the source code, converts the .java files to .class, and stores the classes in the target/classes folder. |
3 | test-compile | Compile the source code in the test destination directory |
4 | test | It runs unit tests for the project. |
5 | package | This step packages the compiled code in a distributable format like JAR or WAR. |
6 | integration-test | It runs the integration tests for the project. |
7 | verify | This step runs checks to verify that the project is valid and meets the quality standards. |
8 | install | This step installs the packaged code to the local Maven repository. |
9 | deploy | It copies the packaged code to the remote repository for sharing it with other developers. |
Command : mvn site
Phase | Description |
pre-site | execute processes needed prior to the actual project site generation |
site | generate the project’s site documentation |
post-site | execute processes needed to finalize the site generation, and to prepare for site deployment |
site-deploy | deploy the generated site documentation to the specified web server |
Phase | Description |
pre-clean | execute processes needed prior to the actual project cleaning |
clean | remove all files generated by the previous build |
post-clean | execute processes needed to finalize the project cleaning |
Phase | Description |
pre-site | execute processes needed prior to the actual project site generation |
site | generate the project’s site documentation |
post-site | execute processes needed to finalize the site generation, and to prepare for site deployment |
site-deploy | deploy the generated site documentation to the specified web server |
More : https://sagarfive.in/maven/maven-site-lifecycle/
mvn help:describe -Dcmd=PHASENAME
mvn help:describe -Dcmd=compile
Example : build in pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.version}</version>
<executions> <execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution> </executions>
</plugin>
</plugins>
</build>
Phase :
Each lifecycle is made up of phases, e.g. for the default lifecycle: compile, test, package, install, etc.
Goal :
The task (action) that is executed. A plugin can have one or more goals.
One or more goals need to be specified when configuring a plugin in a POM. Additionally, in case a plugin does not have a default phase defined, the specified goal(s) can be bound to a phase.
Phase Description
mvn package
This stage packages the compiled code in a distributable format like JAR or WAR
The order of inheritance in Maven(How maven strarts working) is:
In a real time project, a typical deployment process involves the below list of activities:
Manual Process : Each step we have to run the commands
Auto deployment process using maven-release-plugin:
<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/maven-v4_0_0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.webproject</groupId>
<artifactId>SampleWebApp</artifactId>
<packaging>war</packaging>
<version>1.0 </version>
<name>SampleWebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<scm>
<url>http://www.svn.com</url>
<connection>scm:svn:http://localhost:8080/svn/jrepo/trunk/Framework</connection>
<developerConnection>
scm:svn:test/test123@localhost:8080:common_core_api:1101:code
</developerConnection>
</scm>
<distributionManagement>
<repository>
<id>Sample-Web-App-Release</id>
<name>Release repository</name>
<url>
http://localhost:8082/nexus/content/repositories/Sample-Web-App-Release
</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-9</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<scmCommentPrefix>[Sample-Web-App-checkin]</scmCommentPrefix>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
scm | Configures the scm (in this cases SVN is used) of the project |
repositories | Storage location of the WAR/EAR/JAR file after the successful build |
plugin | maven-release-plugin to automate the process |
Maven release plugin :
Maven has two test runs :
Steps :
More info : https://sagarfive.in/maven/maven-unit-testing-using-surefire-plugin/
For more : https://sagarfive.in/maven/maven-integration-testing-using-failsafe-plugin/
Command | Information | |
1 | mvn test | run tests(unit and integration tests) using a suitable unit testing framework These tests should not require the code be packaged or deployed |
2 | mvn -Dtest=TestCircle test | Running a Single a class |
3 | mvn -Dtest=TestCircle#mytest test | Running a specific method in a class |
4 | mvn install -DskipTests or mvn install -Dmaven.test.skip=true | Directly running install command(install the package in local repository) |
Steps :
More info : https://sagarfive.in/maven/maven-unit-testing-using-surefire-plugin/
The order of inheritance in Maven is:
The default directory for the exploded WAR is
Project direcory/target/<finalName> .
Those are the elements we use to identify the artifact and are known as Maven coordinates.
To produce execution debug output you could call Maven with X parameter or e parameter
For Maven <2.0.8, uncomment the following line in your %M2_HOME%/bin/mvn.bat (and maybe save the modified version as mvnDebug.bat):
@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
We can force update in maven by using –U options by using mvn clean install command. In that –U means force update the dependencies of the snapshot. The release dependencies are updated is suppose there are not updated previously.
Commands :
mvn package -U
mvn install -U
A multi-module project is built from an aggregator POM that manages a group of submodules.
In most cases, the aggregator is located in the project’s root directory and must have packaging of type pom.
The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.
More : link
It is your experince interms of years/months
It depends on your experience with maven
If your good enough say 7-7.5
The Maven Scripting Plugin is a plugin that wrapped the Scripting API according to JSR223. Add the scripting engines as dependencies of this plugin on its use.
—
Your ans :
Common issues in Maven include:
i have involved in this build phases
these are explain in above questions
Integration maven with jenkins ,
running maven with jenkins using maven plugin with top level commands
to execute build life cycle and deployment of maven using jenkins
It is automated the workflow of building artifact and deploying to servers
=
No
But I just walk through the internet about alternatives of maven
ANT : it is build tool, we have to develop from strach
Gradle : Gradle used to ruby, java, kotlin
No,
But Now iam planning to learn python, i know a little bit shell scripting(if you know)
To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command:
mvn install -DskipTests
Doxia is used extensively by Maven and it powers the entire documentation system of Maven. It gives Maven the ability to take any document that Doxia supports and output it any format. The current version of Doxia base framework is 1.12.
By enabling parallel execution, the JUnit engine starts using the ForkJoin thread pool.
Next, we need to add a configuration to utilize this thread pool. We need to choose a parallelization strategy.
JUnit provides two implementations (dynamic and fixed) and a custom option to create our implementation.
for more info : link
mvn package – take the compiled code and package it in its distributable format, such as a JAR,
mvn install – install the package into the local repository, for use as a dependency in other projects locally
mvn clean install — clean the previous build information, and rebuild for new artifact
How you upload aritfact to sonatype : link
Your ans _____
more : link