Maven Continued
- Build Profile:
- This is set of configuration values, which can be use to set or override the default values of maven build.
- Types of Build Profile
- Per-Project: Defined in the Project POM file
- Per-User: Defined in the Maven settings file (HOME_DIR/.m2/settings.xml)
- Global: Defined in Maven global settings file (%M2_HOME/conf/settings.xml)
- Refer Here for the usage to set the build profile at project level.
- Now execute the following commands
mvn test
=> executes normally andmvn test -Ptest
- Generally on our build systems or on developer systems in organizations we need to add http proxy details for downloads from maven Refer Here for an article which shows how to active the http proxy
- For the basic structure and schema of settings.xml file Refer Here
- Create a settings.xml in ~/.m2/setting.xml with following content
<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"> <activeProfiles> <activeProfile>test</activeProfile> </activeProfiles> </settings>
- Now execute
mvn test
since we have set active profile as test for the user so -Ptest will be added automatically
Maven Repository
- Maven is used/it is popular because of its dependency management.
- Repository is a directory where all the project jar, library jar, plugins or any other project specific artificats are stored so that Maven can use easily
- Maven Repositories are of three types
- local
- remote
- central
- Local Repository:
- This is folder on every machine where the maven get’s installed
- The default path of it
~/.m2
- Maven local repository keeps your project’s dependencies when you run a mavne build, then maven downloads all the depencieses in to local repository
- Lets discuss about a build goal
install
, in this case your project will be added to the local reposiory - Added sample2 project which depends on sample1
- If sample1 project is not executed with goal install sample2 build will fail
- now if we execute sample1 with goal install which copies the artifacts to local repo then we can use sample1 as dependency in any of the projects for the same user on that system
- Central Repository:
- This is repository provided by maven community, It contains large number of commonly used libraries
- When Maven doesn’t find any dependency in local registry, It starts searching in central repository
https://repo.maven.apache.org/maven2/
- Lets try to add the dependency of junit to our project Refer Here. Refer Here for the change done.