- Build automation tool
- Build
- Compiling
- running unit tests
- running integration tests
- Package jar/war
- Deploy to server
- Uses POM.xml to describe Project, dependencies, build order & plugins.
- Convention over configuration
Commands
- mvn install - install to repository
- Make build process EASY
- Uniform build system
- Describes how software is built
- It is described by POM(Project Object model)
- Describes the dependencies the software has
- Build life cycle- made of up phases
- It is collection of plugins. Plugins perform action in maven.
- It suggest default 'Project Structure' & 'build life cycles'
POM
- General information
- Build settings(Customize the maven lifecycles, add new 'Plugins' and 'Goals')
- Build environment(Profiles used to configure different deployment environments, Dev, Test, Prod)
- POM Relationships(Modules and SubModules)
- Compile - Dependency available in all build phases & packaged with application
- Test - Test complication & execution
- runtime - required only at runtime and not at compile time
- provided - When container provides dependency
- system - Same as provided but you will tell system where exactly is the provided jar
- clean - Cleaning up previous build
- default or build - building and deployment
- site - creating project site documentation
- Clean(3 phases) - Few phases have builtin goals/plugins
- Build(23 Phases)
- Site(
- They have goals associated with it
- help:describe -Dcmd =compile ->
Installation: Env variable setup
export M2_HOME=/Users/vdesu/maven/apache-maven-3.6.2
export PATH=$M2_HOME/bin:$PATH
mvn -version
---
Apache Maven- Most used build management tool/Project management tool.
Building a project means
Why use Maven:
Maven Plugin & Goals: Maven Plugin is group of one or more goals. Each plugin exposes atleast one goal. mvn <plugin name>:<goal name> followed by parameters
export M2_HOME=/Users/vdesu/maven/apache-maven-3.6.2
export PATH=$M2_HOME/bin:$PATH
mvn -version
---
Apache Maven- Most used build management tool/Project management tool.
Building a project means
- Compile
- Run tests
- Package into jar files
- Bundle jar into war files
- Deploy to server
- myproject
- src/main/java
- src/main/resources
- src/test/java
- src/test/resources
Why use Maven:
- Common interface (standard structure)
- Dependencies
- Repositories
Maven Plugin & Goals: Maven Plugin is group of one or more goals. Each plugin exposes atleast one goal. mvn <plugin name>:<goal name> followed by parameters
- archetype:generate
- install:install
- eg: mvn archetype:generate -DgroupId=com.venkat -DartifactId=hellomaven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Maven coordinates
- group id
- artifact id
- packaging
- version
POM: Project Object Model
Maven Build Life cycle:
Core concepts:
Maven Plugins & Goals- Helps to manage all dependency in web application
Maven Build Life cycle:
- Validate -> validate pom.xml
- Compile -> generate .classfiles
- Test -> run the unit tests
- Package -> create jar file
- Integration Test->
- Verify ->
- Install -> install to local repository
- Deploy
Core concepts:
- POM
- Plugins & goals
- Coordinates
- Repositories
- Plugin is collection of one or more goals
- syntax: pluginId:goalId
- eg:
- mvn archetype:generate -DgroupId=com.desu -DartifactId=hellomaven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
- cd hellomaven
- mvn install -> this will compile, run test & package
- java -cp target\hellomaven-1.0-SNAPSHOT.jar com.desu.App
- process-resources > resources:resources
- compile > compiler:compiler
- test > surefire:test
- package > jar:jar
- groupId similar to package name in Java
- artifactId similar to class name in java
- packaging (extension)
- version
- It describes 'how' the software is built.
- It describes 'Dependencies' the software has.
- It is described by 'POM' - Project Object Model - stored in xml format
- Sheilds from build complexities
Maven Build life cycle
- Validate -> Compile -> Test -> Package -> Integration Test -> Verify -> Install -> Deploy
- Create/copu POM.xml in parent folder of the 2 projects(childs)
- Change the artifact id to 'parent', name,
- set Packaging to POM
- Define child projects as Modules
- Make following changes to Child project POM
- Add <parent> element with maven coordinates of Parent
- Build multi module project
-
mvn clean install // builds all 3 projects
- Add <dependency> element incase one project is dependent on other
Scopes
- In dependency tag
- Compile
- default scope
- runtime
- not required for compilation
- provided
- required during test and run locally. Hence not exported to war/jar
- test
- compile & run Tests only
- system
- similar to provided .. but not provided either by maven or system
- import
- used for pom based projects.
No comments:
Post a Comment