Maven (Apache)
Build Tools:
Java
Ant, Maven, Gradle
.Net
Nant, MS Build
Python
Pybuilder
Types of Applications:
Standard Applications
Jar files (java Archive)
It consists of ".class" files
Web Applications:
War files (Web Archive)
It consists of Java code and Web contents like HTML, CSS, JS
Enterprise Applications:
Ear files (Enterprise Archive)
It consists of Multiple modules Java code and Web contents and many War files. And it used for Big enterprises or applications. To create Ear we need to first create War first.
Note: Among the three packages Ear is the bigger one.
Maven Directory Strurcture:
bin
lib
conf
boot
bin -> mvn
lib -> jar files
conf -> setting.xml
Maven installation Pre-Requisite:
Java should be installed
Java installation:
To download Java click on the below link
Step-1: Login as a root user
$ sudo su -
Step-2: Change dir to /opt
# cd /opt
# yum install wget -y
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm
yum install jdk-8u131-linux-x64.rpm -y
Step-3: Check installed java verson
# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
Mavan installation:
To download Maven click on the below link
Step-1: Validate Java installed
$ Java -version
Step-2: login as a root user and change the directory to /opt
$ sudo su -
# cd /opt
Step-2: Download the Maven Software using wget
# wget https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
--2021-01-08 18:53:35-- https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
Resolving mirrors.estointernet.in (mirrors.estointernet.in)... 43.255.166.254, 2403:8940:3:1::f
Connecting to mirrors.estointernet.in (mirrors.estointernet.in)|43.255.166.254|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9602303 (9.2M) [application/zip]
Saving to: ‘apache-maven-3.6.3-bin.zip.1’
apache-maven-3.6.3-bin.zip.1 100%[====================================================================================================>] 9.16M 32.4MB/s in 0.3s
2021-01-08 18:53:35 (32.4 MB/s) - ‘apache-maven-3.6.3-bin.zip.1’ saved [9602303/9602303]
Step-3: [Optional] Set the Classpath or Environment variable
There are two ways you could see the environment variables at the individual user level or for all the users.
Individual user-> .bash-profile
all users -> /etc/profile
Individual user:
# vi ~/.bash_profile
export MAVEN_HOME=/opt/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin
. ~/.bash_profile
# echo $MAVEN_HOME
/opt/apache-maven-3.6.3
All users:
vi /etc/profile
export MAVEN_HOME=/opt/apache-maven-3.6.3
export PATH = $PATH:$MAVEN_HOME/bin
source /etc/profile
Step-4: Check the installed Maven version
# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_131/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.1.1.el8_3.x86_64", arch: "amd64", family: "unix"
What is pom.xml
It's a default build XML file. We can change the file name based on the requirement. For each project, one pom.xml file will exist.
Sample Pom.xml:
<project>
<modelVersion>3.6.0</modelVersion>
<groupId>com.fin01</groupId>
<artifactId>fin01-app-project</artifactId>
<version>1.0.0</version>
<packaging> jar </packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
What happens in the background when you run mvn package?
i) It checks the dependencies which are mentioned in the pom.xml during checks it first checks the Local Repository if it's not available it will check in the Central Repository if that still not find it will search in Remote Repository.
ii) It creates the repository folders
Repositories in Maven:
i) Maven Local Repository
Dir name -> m2/repository
Dir location -> local user home
Defualt path -> ~./m2/repository
ii) Maven Central Repository
you could find the libraries from the central repository which were not found by Mavin in the local repository.
iii) Maven Remote Repository
Companies maintain their own local repositories for all projects within the company. And it is accessible within the company only and restricted outside.
How to change the default path for Maven local repository?
Using setting.xml from the Maven home location
<localRepository>
update the maven local repository path
</localRepository>
Location:
# pwd
/opt/apache-maven-3.6.3/conf
# ls -rlt settings.xml
-rw-r--r--. 1 root root 10468 Nov 7 2019 settings.xml
# cat settings.xml |grep localRepository
<!-- localRepository
<localRepository>/path/to/local/repo</localRepository>
Maven Life Cycles
i) Clean
ii) Site
iii) default
Life Cycle: Clean
Goal Name: Clean -> This Will clean the previous build files
Life Cycle: Site
Goal Name: Site -> It will generate the Doc for the source code
Life Cycle: Default
Goal Name: Validate -> It will check the project structure and resource files.
Compile -> It will compile the source code.
Test -> It will run the unit test cases.
Package -> It will generate the package or build artifacts (like jar, war, and ear).
Install -> It will store the build artifacts into the local repository.
Deploy ->It will store the build artifacts into the remote repository.
Note: The "goal name order" is important in the Default Goal.
MVN Commands
mvn clean
mvn site
mvn validate
mvn compile
mvn test
mvn package
mvn install
mvn deploy
Command-1:
$ mvn package
Output:
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.6-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-stanalone-application ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-stanalone-application ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-stanalone-application ---
[INFO] Surefire report directory: /opt/maven-standalone-application-master/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mt.sample.test.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ maven-stanalone-application ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.848 s
[INFO] Finished at: 2021-01-09T09:40:39Z
[INFO] ------------------------------------------------------------------------
Where package would be created after running the "mvn package"
The package will create in the "TARGET" directory
$ pwd
/opt/maven-standalone-application-master/target
$ ls -rlt
total 4
drwxr-xr-x. 3 root root 35 Jan 9 09:36 maven-status
drwxr-xr-x. 3 root root 17 Jan 9 09:36 classes ----------------------- .Java code . class files
drwxr-xr-x. 3 root root 17 Jan 9 09:36 test-classes ------------------ Junit test cases .class files
drwxr-xr-x. 2 root root 101 Jan 9 09:36 surefire-reports
drwxr-xr-x. 2 root root 28 Jan 9 09:36 maven-archiver
-rw-r--r--. 1 root root 3171 Jan 9 09:36 maven-stanalone-application-0.0.1-SNAPSHOT.jar
Command -2:
$ mvn clean
It will delete the target directory and removes the existing build files
Output:
$ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (3.9 kB at 3.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 kB at 48 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 kB at 83 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-stanalone-application ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom (4.1 kB at 15 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom (8.4 kB at 31 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom (8.4 kB at 31 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar (226 kB at 399 kB/s)
[INFO] Deleting /opt/maven-standalone-application-master/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.235 s
[INFO] Finished at: 2021-01-09T09:59:32Z
[INFO] ------------------------------------------------------------------------
$ ls -rlt --------------------- no target directory exists
total 8
drwxr-xr-x. 4 root root 30 Nov 12 05:54 src
-rw-r--r--. 1 root root 2319 Nov 12 05:54 pom.xml
-rw-r--r--. 1 root root 1 Nov 12 05:54 Jenkinsfile
Command-3:
mvn clean package
It cleans the existing package and creates the build files
Output:
$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-stanalone-application ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-stanalone-application ---
[INFO] Surefire report directory: /opt/maven-standalone-application-master/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mt.sample.test.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.013 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ maven-stanalone-application ---
[INFO] Building jar: /opt/maven-standalone-application-master/target/maven-stanalone-application-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.949 s
[INFO] Finished at: 2021-01-09T10:03:28Z
[INFO] ------------------------------------------------------------------------
How to skip running the unit test cases? Or how to reduce the build time?
mvn clean package -DskipTests
the above command will skip the unit test cases. Though it skips the unit test cases but it compiles the unit test cases which is not required to do. Generally, we compile them when we run the unit test cases.So how to avoid compiling the unit test cases.
To avoid compiling unit test cases use the below command:
mvn clean package -Dmaven.test.skip=true
$ mvn clean package -DskipTests
Output:
$ mvn clean package -DskipTests
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-stanalone-application ---
[INFO] Deleting /opt/maven-standalone-application-master/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-stanalone-application ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ maven-stanalone-application ---
[INFO] Building jar: /opt/maven-standalone-application-master/target/maven-stanalone-application-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.171 s
[INFO] Finished at: 2021-01-09T10:11:13Z
[INFO] ------------------------------------------------------------------------
$ mvn clean package -Dmaven.test.skip=true
Output:
$ mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-stanalone-application ---
[INFO] Deleting /opt/maven-standalone-application-master/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-stanalone-application ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-stanalone-application ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-stanalone-application ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ maven-stanalone-application ---
[INFO] Building jar: /opt/maven-standalone-application-master/target/maven-stanalone-application-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.203 s
[INFO] Finished at: 2021-01-09T10:19:44Z
[INFO] ------------------------------------------------------------------------
Note: Post the above command you don't see "test-classes" directory
How to use the custom repository as my Maven local repository
Go to the maven software installation directory config location and modify the "setting.xml" file
add these lines into the setting.xml file.
<localRepository>/opt/apache-maven-3.6.3/mavencustomlocalrepo</localRepository>
# pwd
/opt/apache-maven-3.6.3/conf
# ls -rlt
total 16
-rw-r--r--. 1 root root 3747 Nov 7 2019 toolchains.xml
drwxr-xr-x. 2 root root 37 Nov 7 2019 logging
-rw-r--r--. 1 root root 10549 Jan 9 10:40 settings.xml
post modification of custom maven local repository run the below command to creat the m2 repository to the defined location.
$ mvn clean package
it will download all the dependencies into the new repository from the beginning. If you want to avoid downloading and use the existing dependencies, you could copy the existing dependencies into the newly default custom location.
Output:
Command-3:
$ mvn clean install
It will execute, validate, compile, test, package and install . It will store your build artifacts into the local repository.
It will store based on the group id (com.)
local repository :
/opt/apache-maven-3.6.3/mavencustomlocalrepo/com
Output:
# mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.mt:maven-stanalone-application >-----------------
[INFO] Building maven-stanalone-application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (6.4 kB at 6.3 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar (27 kB at 98 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-stanalone-application ---
[INFO] Deleting /opt/maven-standalone-application-master/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-stanalone-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-standalone-application-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-stanalone-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/maven-standalone-application-master/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-stanalone-application ---
[INFO] Surefire report directory: /opt/maven-standalone-application-master/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mt.sample.test.HelloWorldTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ maven-stanalone-application ---
[INFO] Building jar: /opt/maven-standalone-application-master/target/maven-stanalone-application-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ maven-stanalone-application ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (2.5 kB at 11 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom (19 kB at 75 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom (1.1 kB at 4.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom (5.0 kB at 21 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom (7.2 kB at 29 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (7.3 kB at 31 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar (38 kB at 126 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar (12 kB at 22 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (230 kB at 263 kB/s)
[INFO] Installing /opt/maven-standalone-application-master/target/maven-stanalone-application-0.0.1-SNAPSHOT.jar to /opt/apache-maven-3.6.3/mavencustomlocalrepo/com/mt/maven-stanalone-application/0.0.1-SNAPSHOT/maven-stanalone-application-0.0.1-SNAPSHOT.jar
[INFO] Installing /opt/maven-standalone-application-master/pom.xml to /opt/apache-maven-3.6.3/mavencustomlocalrepo/com/mt/maven-stanalone-application/0.0.1-SNAPSHOT/maven-stanalone-application-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.401 s
[INFO] Finished at: 2021-01-09T11:29:14Z
[INFO] ------------------------------------------------------------------------
Validate the build files
# ls -rlt /opt/apache-maven-3.6.3/mavencustomlocalrepo/com/mt/maven-stanalone-application/0.0.1-SNAPSHOT
total 16
-rw-r--r--. 1 root root 2319 Nov 12 05:54 maven-stanalone-application-0.0.1-SNAPSHOT.pom
-rw-r--r--. 1 root root 3171 Jan 9 11:29 maven-stanalone-application-0.0.1-SNAPSHOT.jar
-rw-r--r--. 1 root root 238 Jan 9 11:29 _remote.repositories
-rw-r--r--. 1 root root 719 Jan 9 11:29 maven-metadata-local.xml
How to do a build for a specific module?
Get the list of module/modules from pom.xml (parent) and specify them with "pl", where pl is the project list.
$ mvn clean package -pl <module-name>
Where pl is the project list
Output:
# mvn clean package -pl MavenEnterpriseApp-web
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.mt:MavenEnterpriseApp-web >--------------------
[INFO] Building MavenEnterpriseApplication 1.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenEnterpriseApp-web ---
[INFO] Deleting /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenEnterpriseApp-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ MavenEnterpriseApp-web ---
[INFO] Compiling 1 source file to /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenEnterpriseApp-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ MavenEnterpriseApp-web ---
[INFO] Compiling 1 source file to /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenEnterpriseApp-web ---
[INFO] Surefire report directory: /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mt.TestController
Jan 09, 2021 6:35:34 PM org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register
INFO: Mapped "{[/],methods=[GET]}" onto public java.lang.String com.mt.HelloWorldController.hello(org.springframework.ui.ModelMap)
Jan 09, 2021 6:35:35 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: org.springframework.test.web.servlet.setup.StubWebApplicationContext@9f70c54
Jan 09, 2021 6:35:35 PM org.springframework.mock.web.MockServletContext log
INFO: Initializing Spring FrameworkServlet ''
Jan 09, 2021 6:35:35 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet '': initialization started
Jan 09, 2021 6:35:35 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet '': initialization completed in 3 ms
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.761 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ MavenEnterpriseApp-web ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MavenEnterpriseApp-web] in [/opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target/MavenEnterpriseApplication]
[INFO] Processing war project
[INFO] Copying webapp resources [/opt/maven-enterprise-application-master/MavenEnterpriseApp-web/src/main/webapp]
[INFO] Webapp assembled in [90 msecs]
[INFO] Building war: /opt/maven-enterprise-application-master/MavenEnterpriseApp-web/target/MavenEnterpriseApplication.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.726 s
[INFO] Finished at: 2021-01-09T18:35:36Z
[INFO] ------------------------------------------------------------------------
Comments
Post a Comment