maven知識總結

一、maven的優勢,下載,加載順序

    a)       約定優於配置

    b)       簡單

    c)       測試支持

    d)       構建簡單

    e)       CI

    f)    插件豐富

    2.      下載

        a)       https://maven.apache.org/download.cgi

        b)     安裝

超級pom,pom的級聯關係src/main/java是在這個地方規定的

    c)       maven-model-builder-3.3.9.jar/org/apache/maven/model

    d)       配置  MVM_HOME

           i.        Windows  path

            ii.        Linux  .bash_profile

             iii.        MAVEN_OPTS

          iv.        配置setting.xml

<mirror> 

              <id>alimaven</id> 

              <name>aliyun maven</name> 

             <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 

              <mirrorOf>central</mirrorOf>         

            </mirror>

            <mirror>

                  <id>ui</id>

                  <mirrorOf>central</mirrorOf>

                  <name>HumanReadable Name for this Mirror.</name>

                  <url>http://uk.maven.org/maven2/</url>

            </mirror>

            <mirror>

            <id>osc</id>

           <mirrorOf>central</mirrorOf>

           <url>http://maven.oschina.net/content/groups/public/</url>

        </mirror>

        <mirror>

            <id>osc_thirdparty</id>

           <mirrorOf>thirdparty</mirrorOf>

           <url>http://maven.oschina.net/content/repositories/thirdparty/</url>

       </mirror>



二、maven的傳遞依賴和作用域(轉載)

https://blog.csdn.net/elricboa/article/details/70199727

三、maven仲裁管理:(轉載)

https://blog.csdn.net/wanyanxgf/article/details/6617403

四、maven 生命週期 lifecycle/phase/goal

lifecycle,phase,goal以及mojo之間的作用和區別,可以參考下面這篇博客:

https://blog.csdn.net/glory1234work2115/article/details/51570073

1.A BuildLifecycle is Made Up of Phases

2.A BuildPhase is Made Up of Plugin Goals



五、     版本管理

a)       1.0-SNAPSHOT

           i.        repository 刪除

            ii.        mvn cleanpackage -U (強制拉一次)

b)       主版本號.次版本號.增量版本號-<里程碑版本>

1.0.0-RELAESE

六、   常用命令

a)      mvn clean compile

b)       mvn clean    刪除target/

c)      mvn clean test       test case junit/testNG

d)        mvn clean package 打包

e)       mvn clean  install    把項目install到local repo

f)    mvn deploy   發本地jar發佈到remote

七、    插件

a)       常用插件

        i.        https://maven.apache.org/plugins/

       ii.        http://www.mojohaus.org/plugins.html

     iii.        findbugs 靜態代碼檢查

https://blog.csdn.net/Fancy_xty/article/details/51718687(idea中安裝findbug插件)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <!-- <configLocation>${basedir}/springside-findbugs.xml</configLocation> -->
        <threshold>High</threshold>
        <effort>Default</effort>
        <findbugsXmlOutput>true</findbugsXmlOutput>
        <!-- findbugs xml輸出路徑-->
        <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>
    </configuration>
</plugin>

     iv.        versions 統一升級版本號

1.    mvnversions:set -DnewVersion=1.1

       v.        source 打包源代碼(插件)

<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <phase>install</phase>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
        </execution>
    </executions>
</plugin>

      vi.        assembly 打包zip、war

       vii.        tomcat7

八、      自定義插件 https://maven.apache.org/guides/plugin/guide-java-plugin-development.html

參考文檔:https://blog.csdn.net/z69183787/article/details/52982249

  1. dependency>
  2. <groupId>org.apache.maven</groupId>
  3. <artifactId>maven-plugin-api</artifactId>
  4. <version>2.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.maven.plugin-tools</groupId>
  8. <artifactId>maven-plugin-annotations</artifactId>
  9. <version>3.2</version>
  10. <scope>provided</scope>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.codehaus.plexus</groupId>
  14. <artifactId>plexus-utils</artifactId>
  15. <version>3.0.8</version>
  16. </dependency>
一定要依賴這兩個jar包

a)  <packaging>maven-plugin</packaging>

b)  extendsAbstractMojo

c)  

d)  mvn install

e)  參數傳遞

九、        Profile

a)  使用場景dev/test/pro

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <profiles.activation>dev</profiles.activation>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <profile>
        <id>test</id>
        <properties>
            <profiles.activation>test</profiles.activation>
        </properties>
    </profile>
    <profile>
        <id>prd</id>
        <properties>
            <profiles.activation>prd</profiles.activation>
        </properties>
    </profile></profiles>
build>
    <finalName>winner-mvn-profile</finalName>
    <resources>
        <resource>
            <directory>src/main/resources/${profiles.activation}</directory>
        </resource>
    </resources></build>
mvn install -Ptest 就是打包 test/* 即test目錄下的所有文件 

具體配置,參考這個博客:http://blog.51cto.com/xiaok007/1907509

b)  setting.xml 家和公司兩套

4.         倉庫

maven構建私服:https://blog.csdn.net/shenshen123jun/article/details/9084293

a)  下載

b)  安裝 解壓

c)  使用http://books.sonatype.com/nexus-book/reference3/index.html

localhost:8081,賬號admin/admin123

             i.        http://192.168.1.6:8081/nexus

            ii.        admin/admin123

d)  發佈

             i.        pom.xml 配置

1.   

2.   

e)  下載jar配置

             i.        配置mirror

            ii.        Profile

十、     archetype  模版化

可以參考博客:https://www.aliyun.com/jiaocheng/581611.html

a)  生成一個archetype

             i.        mvn archetype:create-from-project

            ii.        cd /target/generated-sources/archetype

          iii.        mvn install

b)  從archetype創建項目 mvnarchetype:generate -DarchetypeCatalog=local

查看系統變量:mvn help:system(idea終端窗口輸入)

打包傳參方式:mvn install -Dargs=123   args是一個參數名

maven統一給css,和js文件打上版本號,參考這個文檔:

https://my.oschina.net/u/140938/blog/1553604


 



發佈了39 篇原創文章 · 獲贊 5 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章