This post provides a step-by-step guide with a list of commands on how to install Maven on macOS using Homebrew. What is Maven? Maven is a build automation tool used primarily for Java projects.
Maven Install on Mac OS X. Ask Question Asked 7 years, 9 months ago. Active 5 months ago. Bgvp dm6 vs dmg 3. Download Maven from its homepage; Follow the installation instructions: Extract the distribution archive, i.e.apache-maven-3.3.9-bin.tar.gz to the directory you wish to install Maven 3.3.9. It is strongly recommended to use the latest release version of Apache Maven to take advantage of newest features and bug fixes. If you still want to use an old version you can find more information in the Maven Releases History and can download files from the archives for versions 3.0.4+ and legacy archives for earlier releases.
for Java, Jenkins, etc.
- Install latest
- Using Maven
This describes how to install Maven using Homebrew, the configure and use it.
Maven is a task runnner, like Ant, Gradle, Grunt.
Unlike Ant, Maven also provides dependency management, standard project layout, and project management.
Default in Jenkins
Maven is the default build tool in the Jenkins continuous integration tool which triggers a Maven build whenever code is committed.
Mated with Java
Maven is written in Java, and grew up supporting Java buildsby creating from Java source and resources for deploymentdeliverables like JAR file or WAR files.
So Maven is the default for the Jenkins continuous integration tool whichtriggers a Maven build whenever developer commit code. Download anki 2.0.
Maven adopts the principle of “Convention over configuration”, which means less coding work.
Read more: http://javarevisited.blogspot.com/2015/01/difference-between-maven-ant-jenkins-and-hudson.html#ixzz4CQKSY3oF
Install latest
- To install the latest version:brew update
brew install maventhe response I got on Dec 29, 2017:Alternately:Install previous version
Alternately, toinstall a previous version:brew install homebrew/versions/maven30Then, to switch among versions:brew unlink maven30 && brew link maven
brew unlink maven && brew link maven30Configure Path
- Verify install:mvn -versionI got this response:
- Confirm the path:which mvnresponse:NOTE: Before OSX Mavericks,Maven was installed by default in:
/usr/share/maven/bin/mvn - Confirm the path. Substitute the version (3.5.2) with the versionyou just installed:cd /usr/local/Cellar/maven/3.5.2/libexec
cd bin
lsmvn files should be listed: - Open using a text editor, substituting subl (for Sublime) with atom or vim:cd $HOME
subl .bash_profile - Add the following to under export PATH=, changing the version (3.5.2) to whatever appears above:export M2_HOME=/usr/local/Cellar/maven/3.5.2/libexec
export M2=$M2_HOME/bin
export PATH=$PATH:$M2_HOME/binOn Windows, define enviornment variableM2_HOME
with a path such as:Within enviornment variablePATH
, add: - View changed environment variables. On a Mac:echo $M2_HOMEThe response if installed by Homebrew on Mac:
/usr/local/Cellar/maven/3.5.2/libexec
echo $M2The response if installed by Homebrew on Mac:/usr/local/Cellar/maven/3.5.2/libexec/bin
echo $PATHOn Windows: - In a Terminal, verify changes:echo $JAVA_HOMEThe reply is, for example:
Change Default Configurations
- Navigate to the hidden folder Maven installedto house packages installed (junit, commons-cli, commons-lang, etc).cd ~/.m2/repository</tt>Some prefer to change Maven’s local repository to another location.See https://maven.apache.org/guides/mini/guide-configuring-maven.htmlThere is a settings.xml file containing:
Using Maven
Maven allows use of a central maven repository.
The pom.xml (Project Object Model) file describes project dependencies which Maven resolves by downloading them.
NOTE: Some prefer to install and use the Cargo plugin (from Codehaus) to Maven in order to eliminate use of pom.xml. In a folder that contains a pom.xml:
mvn clean verify org.codehaus.cargo:cargo-maven2-plugin:run
https://codehaus-cargo.atlassian.net/wiki/spaces/CARGO/pages/491622/Maven2+Plugin+Reference+Guide
- The vast majority of Maven-built projects can be built with this command:mvn clean installThe “clean” cleans out results from the prior build before starting with install.During the first full run, testing jars are installed in your local maven repository.
- Maven is said to also act as project management tool becauseit can generate reports etc.build.xmlMaven enforces a standard naming convention for artifacts defined usinggroupId, artifactId, and version.
- After the first run, builds can skip tests with this additional parameter:https://treetalking345.weebly.com/how-to-max-out-your-health-and-dmg-in-the-division.html. mvn clean install -Dmaven.test.skip=true
Maven lifecycle phases
Here are sub-commands for mvn:
Default Lifecycle:
Sub-command | Description |
---|---|
validate | Validate the project is correct and all necessary information is available |
initialize | initialize build state, (for example : set properties, create directories,… etc) |
generate-sources | generate any source code for inclusion in compilation |
process-sources | process the source code (for example : filter any values) |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation (for example : to do bytecode enhancement on Java classes) |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code (for example : to filter any values) |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory. |
process-test-classes | post-process the generated files from test compilation (for example : to do bytecode enhancement on Java classes) |
test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
prepare-package | perform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package. |
package | Take the compiled code and package it in its distributable format (for example : jar, war, …etc) |
pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
Clean Lifecycle:
Sub-command | Description |
---|---|
pre-clean | Executes 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 |
Site Lifecycle:
Sub-command | Description |
---|---|
pre-site | Executes processes needed prior to the actual project site generation. |
site | Generates the project’s site documentation. |
post-site | Executes processes needed to finalize the site generation, and to prepare for site deployment. |
site-deploy | Deploys the generated site documentation to the specified web server. |
See
- http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
- http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html
Maven plug-in goals by lifecycle phase
Each unit of execution work in Maven is called a goal.
Maven C/C++ Plugin http://duns.github.io/maven-nar-plugin/
Maven plug-ins by lifecycle phase
Dependencies
- http://www.sonatype.com/resources/books/maven-by-example
- https://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html
- http://www.sonatype.com/resources/books/maven-the-complete-reference
Mirror
See https://maven.apache.org/guides/mini/guide-mirror-settings.html
The Maven Central Repository provides a UI to
the mirror website where Maven pulls files from.In the US it is:
the mirror website where Maven pulls files from.In the US it is:
- http://repo.maven.apache.org/maven2
The UK mirror supports Europe:
- http://uk.maven.org/maven2
Download Maven Mac Terminal
Others:
http://repo.maven.apache.org/maven2/.meta/repository-metadata.xml
http://repo.maven.apache.org/maven2/.meta/repository-metadata.xml
Build Profiles
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Download Maven 3.1.1 Mac
References
http://www.mkyong.com/tutorials/maven-tutorials/is a compelling resource.
More on OSX
This is one of a series on Mac OSX:
Please enable JavaScript to view the comments powered by Disqus.