zoukankan      html  css  js  c++  java
  • MAVEN学习笔记(一)

        公司项目中用到MAVEN,具体的话,其实只用到了MAVEN的几个简单命令,mvn clean,mvn package,mvn install, mvn deploy。一直也没怎么花时间去看这到底是什么样的东西(其实还是懒)。

        maven,简单来说就是一个java项目构建工具,最常用的功能可能就是解决了各个项目对jar包的依赖这一大痛点。由于语言是java的原因,所以一个项目中往往会引入很多的开源jar包,每一个jar又存在版本等等问题,所以想想也是醉了。再然后由于我个人做java开发也不是很久,所以没用过ant(这也是一个项目构建工具,诞生早于maven),然后现在最新的构建工具可能是Gradle吧,前段时间在看spring framework的源码,https://github.com/spring-projects/spring-framework 已经在使用这个构建工具了。

      

        我们访问maven的官网 https://maven.apache.org/ 在DOCUMENTATION下的index(catagory)下可以查看官方的一些文档。其中introductions 讲解了一些maven中常见的核心概念。

        这里我比较关注 build lifecycle,也就是maven构建项目的生命周期。

        有三种内置的构建声明周期:default,clean和site。

        default声明周期处理项目的部署,clean处理项目的清理,site处理项目文档的创建。

        Build Lifecycle是由phases构成的,default Build Lifecycle中几个重要的phase  

    validate 验证项目是否正确以及必须的信息是否可用
    compile 编译源代码
    test 测试编译后的代码,即执行单元测试代码
    package 打包编译后的代码,在target目录下生成package文件
    integration-test 处理package以便需要时可以部署到集成测试环境
    verify 检验package是否有效并且达到质量标准
    install 安装package到本地仓库,方便本地其它项目使用
    deploy 部署,拷贝最终的package到远程仓库和替他开发这或项目共享,在集成或发布环境完成

        以上的phase是有序的(注意实际两个相邻phase之间还有其他phase被省略,完整phase见lifecycle),下面一个phase的执行必须在上一个phase完成后若直接以某一个phase为goal,将先执行完它之前的phase,如mvn install, 将会先validate、compile、test、package、integration-test、verify最后再执行install phase。

      

        关于maven的核心概念等等可以看这篇博客   http://www.trinea.cn/android/maven/  其中关于goal的解释我不大认同,大家可以看一下maven官方对其的解释:

    A Build Phase is Made Up of Plugin Goals

    However, even though a build phase is responsible for a specific step in the build lifecycle, the manner in which it carries out those responsibilities may vary. And this is done by declaring the plugin goals bound to those build phases.

    A plugin goal represents a specific task (finer than a build phase) which contributes to the building and managing of a project. It may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation. The order of execution depends on the order in which the goal(s) and the build phase(s) are invoked. For example, consider the command below. The clean and package arguments are build phases, while the dependency:copy-dependencies is a goal (of a plugin).

    mvn clean dependency:copy-dependencies package

    If this were to be executed, the clean phase will be executed first (meaning it will run all preceeding phases of the clean lifecycle, plus the clean phase itself), and then the dependency:copy-dependencies goal, before finally executing the package phase (and all its preceeding build phases of the default lifecycle).

    Moreover, if a goal is bound to one or more build phases, that goal will be called in all those phases.

    Furthermore, a build phase can also have zero or more goals bound to it. If a build phase has no goals bound to it, that build phase will not execute. But if it has one or more goals bound to it, it will execute all those goals

    (Note: In Maven 2.0.5 and above, multiple goals bound to a phase are executed in the same order as they are declared in the POM, however multiple instances of the same plugin are not supported. Multiple instances of the same plugin are grouped to execute together and ordered in Maven 2.0.11 and above).

    我认为maven命令是基于plugins的,而goal是对该pilugin实现的功能的一个简要描述,phase与plugin的goal绑定在一起,这样执行mvn -phase时才能执行。

  • 相关阅读:
    IIS Express 配置缓存位置
    Docker Demo on Docker
    前端的哪些坑
    如何在container中编译dotnet的eShopOnContainers
    JQuery 常用的那些东西
    jQuery选择器大全
    Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
    WPF 通过透明度遮罩和变换制作倒影效果
    Ons 让人欲哭无泪问题,官方介绍不详
    如何转换任何配置文件 文件中的内容
  • 原文地址:https://www.cnblogs.com/vikeria/p/4890224.html
Copyright © 2011-2022 走看看