Maven is used for project management and builds.
It contains a Project Object Model, a set of standard collections, a ProjectLifecycle, a Dependency Management System, and a plugin for running plugins defined in phases of the lifecycle (plugin) The logic of the goal (goal).
Default repository definition and location
~/.m2/settings.xml
This file contains configuration for user-related authentication, repositories, and other information to customize Maven's behavior.
~/.m2/repository/
This directory is your local repository. When you download a dependency from a remote Maven repository, Maven stores a copy of the dependency in your local repository.
Bring your own remote warehouse address: http://repo1.maven.org/maven2
Eclipse M2Eclipse maven plugin
http://m2eclipse.sonatype.org/sites/m2e
http://eclipse.org/m2e/download/
http://download.eclipse.org/technology/m2e/releases/1.3/?d
mave coordinates
groupId,artifactId, packaging, versionpackaging
Default is jar
Scope
test : will only be added to the classpath when running test targets such as compiler:testCompile and surefire:test
provided: The dependency is required at compile time, but it should not be bundled in the build output, such as the Servlet API
Order
mvn -v View version information, you need to configure M2_HOME, and add %M2_HOME%/bin to the path
mvn --help
mvn install builds and packages
mvn install -X runs with the debug flag to view the complete dependency trace, and prints the components that were rejected due to conflicts or other reasons
mvn clean install cleans first, then cleanly builds
mvn help:effective-pom Shows the POM that Maven really runs on, it contains some default configurations mvn package Same as
mvn resources:resources\
compiler:compile\
resources:testResources\
compiler:testCompile\
surefire:test\
jar:jarmvn site Generate documentation and reports
mvn dependency:resolve prints a list of dependencies
mvn dependency:tree Same as above, the entire dependency tree
mvn test runs unit tests The test target executes everything in the project that can be found in src/test/java and whose filenames match **/Test*.java, **/*Test.java and **/*TestCase.java unit test test -Dmaven.test.failure.ignore=true mvn install -Dmaven.test.skip=true
mvn install assembly:assembly will also put the dependencies into the jar package, and the execution result of java -cp common-*.jar com.xxx.Main
mvn exec:java -Dexec.mainClass=org.*.Main run class mvn help:describe -Dplugin=exec -Dfull View full description of Exec plugin (Exec plugin allows you to run Java classes and other scripts. It is not a Maven core plugin)
mvn hibernate3:hbm2ddl construct database using Hibernate3 plugin
mvn dependency:analyze analyze dependencies
mvn site:run generate site
other
1. maven transitive dependencies;
2. Optimize dependencies: the dependencyManagement definition version in the parent project; /pluginManagement
3. Optimized dependencies: If more than one project depends on a specific dependency, it can be listed in dependencyManagement;
4. Optimization plugin: properties definition version
Plugin test
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore> <skip>true</skip>
</configuration>
</plugin>
</plugins>
jar package
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
Jetty mvn jetty:run
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
Hibernate mvn hibernate3:hbm2ddl not tested
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
</configuration>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
</plugin>
compile
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Example:
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.5.ga</version> <exclusions> <exclusion> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency>
Specifies the encoding of the source code
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
Check the version of the install plugin
mvn -Dplugin=install help:describe
skip test
-Dmaven.test.skip=true or -DskipTests=true
test only one
-Dtest=MyTest
Specifies the encoding of the site
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>XXXX</version> <configuration> <outputEncoding>UTF-8</outputEncoding> </configuration> </plugin>
tools.jar
<profiles> <profile> <id>default-tools.jar</id> <activation> <property> <name>java.vendor</name> <value>Sun Microsystems Inc.</value> </property> </activation> <dependencies> <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.4.2</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> </dependencies> </profile> </profiles>
Source code SVN
http://svn.apache.org/viewvc/maven/maven-2/branches/maven-2.2.x http://svn.apache.org/viewvc/maven/maven-3/trunk