个人觉得很好用的maven命令

maven 常用命令

创建一个简单的maven项目

mvn archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-site \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app-site

maven 处理依赖的方式

使用构建命令

packageinstall 两个命令都会下载依赖包.

clean

clean remove the target filder

package

package will compile your code and also package it. For example, if your pom says the project is a jar, it will create a jar for you when you package it and put it somewhere in the target directory (by default).

install

install will compile and package, but it will also put the package in your local repository. This will make it so other projects can refer to it and grab it from your local repository.

install phase comes after package phase

update repository after adding dependency

If you want to only download dependencies without doing anything else, then it’s:

mvn dependency:resolve

Or to download a single dependency:

mvn dependency:get -Dartifact=groupId:artifactId:version

If you need to download from a specific repository, you can specify that with -DrepoUrl=…

mvn install (or mvn package) contains update repository

mvn compile to download compile time dependencies or mvn test for compile time and test dependencies

other

  1. 显示一级依赖

    mvn dependency:tree

  2. -Dverbos 显示多级依赖

    mvn dependency:tree -Dverbos

  3. -Dincludes 指定包
  4. -Dexcludes 排除指定包

找出依赖关系后在pom.xml文件中利用标签\<exclusions>排除相应的依赖

<dependency>
    <groupId>org.unitils</groupId>
    <artifactId>unitils-dbmaintainer</artifactId>
    <version>${unitils.version}</version>
    <exclusions>
        <!-- 排除相应的依赖 -->
        <exclusion>
            <artifactId>dbunit</artifactId>
            <groupId>org.dbunit</groupId>
        </exclusion>
        <exclusion>
            <artifactId>asm</artifactId>
            <groupId>asm</groupId>
        </exclusion>
    </exclusions>
</dependency>

REFERENCE

Published
Categorized as tool

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.