Maven
-
Java distribution formats
- JAR
- WAR
- EAR
-
Maven manages
- libraries
- compiles the commands
- test execution
- packaging
- Maven solves this by using conventions over configuration
- a standard folder structure
- pom.xml file
- ready made commands
- Heart of maven (pom.xml) which tells maven
- project name
- version
- dependencies
- build settings
- plugins
- Important fields of pom.xml
- groupId: This represents organization
- artifactId: name of your project
- version: Version of your application
-
Standard Maven Project Structure
-
Maven lifecycle:
- we dont tell maven every tiny step, we tell it a stage and it performs that stage pluse required early stages
- Important phases
- validate
- compile
- test
- package
- verify
- install
- deploy
- Commands
mvn compilefor compile phasemvn packagefor package phasemvn clean package
- Maven generates artifacts into target folder
-
In maven project we can specify dependencies and it downloads dependencies into
~/.m2/repositorywhich can be changed with envM2_HOME -
Maven requires Java to work
- Lets install jdk 21
- Maven prompt =>
give me steps to install latest maven on ubuntu 24
Dependencies
- JAVA:
- mvn => resolve depdencies
- Dotnet
- nuget
- Python
- pip
- node js
- npm
Artifacts and .gitignore
- Artifacts are build outputs
- Any files that are generate during build/test should not end up in git repo
- To ensure unnecessary files dont end up in git repo we create
.gitignorefile
Github actions pipeline
- Which on pull request to dev branch will ensure all the tests are passing
- Refer Here
- Lets enhance this pipeline to show the test results
- Refer Here to the changes over here
Static code analysis
- Most of orgs use static code analysis tools such as
- sonarqube
- codeql
Codeql
- Github provides its own built-in static code analysis tool called codeql
Exercise
- Fork the spring petclinic repo
- remove existing github actions
- create a new workflow for pull request
- Ensure you perform all the checks ref
- tests
- codeql
- use this as Refer Here
- Inspired by this try doing the same for .net repository
