maven in action
maven phases and plugins goal
three built-in Lifecycle
- default
- clean
- site
built-in Lifecycle is made up of phases
- default
- validate - validate project is correct and all neccessary infomation is avaiable
- compile
- test
- package
- integration-test
- verify - run and checks to verify the package is valid and meets quality criteria
- install - install to local repository
- deploy - copy the final package to the remote repository for sharing.
a build phase is made up of plugin goals
- a plugin goal represents a specific task, and bound to those build phases.
- it’s bound to zero or more build phases
mvn clean dependency:copy-dependencies package
- a phase can also have zero or more goals bound to it. if a build phase has no goals bound to it, it cannot execute.
编写插件的时候,我们会给每一个goal默认绑定一个phase,所以在对应的plugin中,我们或许不需要显式绑定两者
maven core concept: coordinate and dependency
coordinate
- groupId
- artifactId
- version
- packaging - jar(default), war
- classfier - javadoc.jar, sources.jar. cannot defined directly
dependency
- dependency scope: (compile, test, provided, runtime, system, import), provided(servlet-api) system should with systemPath.
- transitive dependency
- dependency mediate (the shortest path, otherwise declartive order in pom)
- execlusion dependency(groupId & artifactId)
How to look for dependency
mvn dependency:list mvn dependency:tree
mvn dependency:analyze
: 标注声明但未使用的依赖或者使用但未声明的依赖(传递依赖)
dependency management
1 | <dependencyManagement> |
防止subModules继承不必要的依赖,同时如果需要,只要在subModule中声明此依赖的groupId, artifactId,无需对应的versionId,因为这是可以继承自parentModule的