【玩转java】Maven常用命令和插件

100 阅读1分钟

命令

  • maven构建中的几个主要的phase:compile test package install
  • mvn clean install或者mvn clean install -U(强制更新SNAPSHOT的依赖包)
  • mvn dependency:tree

插件

  • 插件是什么:maven其实是一套框架,所有的具体任务都是插件完成的。除了核心的编译打包插件,还有非常多的别的目的的插件。
  • 打出fatjar的插件
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.alibaba.jvm.sandbox.Clock</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>