[] Maven plugin and dependency management

1. Plugin Manager

  • Defined
    pluginManagement used for plug-in management. It is a plug-in statement that you declare under pluginManagement plug-in project, Maven does not load the plug-in, pluginManagement statement can be inherited .
  • Apply
    to the parent POM defined in the following, to the sub use POM, POM child can also cover this definition, and you define the version in the parent POM, the sub-module direct application groupId and artifactId, without specifying the version, but also facilitate unified management.
父POM
<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>
Sub POM
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
    </plugin>
</plugins>
  • The difference plugins
    is directly introduced into a plugin , and can be bound to the life cycle of related Maven

2.pluginManagement mainly to the unified management plug-in, plug-in versions to ensure that all sub-POM using consistent, similar dependencies and dependencyManagement.

3.maven default plug-ins

When you create a maven project, maven framework project itself provides a default basis plugins in Maven major application lifecycle (lifecycle).

 

4.maven perform tasks such as packing and running

There are two ways:

    • The package execution commands such as Lifecycle
       

Using third-party plug-ins
(1) using a similar tomcat7 plug, pom.xml file configuration.

<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <port>8080</port>
                    <path>/</path>
                    <uriEncoding>UTF-8</uriEncoding>
                    <finalName>mobile</finalName>
                    <server>tomcat7</server>
                </configuration>
            </plugin>

(2)执行插件相关的命令:

(3)有一些特特殊情况,需要通过执行命令实现,比如测试代码不需要打包:
首先:先进行配置
在菜单栏Run---->Edit Configurations中,点击+为Maven进行配置,或者从右上角入口。
其次:配置情况:

最后:相关的命令:

  • 打包
    clean deploy -DskipTests
    clean package -DskipTests
  • 安装jar
    install -DskipTests
  • 运行
    tomcat7:run

Guess you like

Origin www.cnblogs.com/wpcnblog/p/11968936.html