首页 > 代码库 > Maven插件
Maven插件
1. 内置绑定插件:maven在核心为一些生命周期阶段绑定好了一些插件
插件不一定要绑定在生命周期的某个阶段上,如mvn dependency:tree|mvn help:describe
2. 自定义绑定插件:
配置插件时可以省略版本信息,maven会自动匹配最新的插件
maven插件
<build><plugins><plugin></plugin></plugins></build>
<plugin>
groupId 如果Maven官方插件(即groupId为org.apache.maven.plugins),groupId可以省略
artifaceId
version
configuration 插件参数
executions 配置插件任务(在生命周期中某个阶段执行某任务,如果不配置这个标签,该插件就为全局插件)
<execution>
id 插件执行任务的名字
phase 插件绑定执行的生命周期的某个阶段
goals 插件执行任务的目标
configuration 插件执行任务的参数
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>attach-sources</id> 插件执行任务的名字
<phase>verify</phase> 插件绑定执行的生命周期的某个阶段
<goals> 插件执行的目标
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3. 使用maven-help-plugin插件查看插件信息:
====================================
Name: Maven Help Plugin
Description: The Maven Help plugin provides goals aimed at helping to make
sense out of the build environment. It includes the ability to view the
effective POM and settings files, after inheritance and active profiles have
been applied, as well as a describe a particular plugin goal to give usage
information.
Group Id: org.apache.maven.plugins
Artifact Id: maven-help-plugin
Version: 2.2
Goal Prefix: help
This plugin has 9 goals:
help:active-profiles
Description: Displays a list of the profiles which are currently active for
this build.
help:all-profiles
Description: Displays a list of available profiles under the current
project.
Note: it will list all profiles for a project. If a profile comes up with a
status inactive then there might be a need to set profile activation
switches/property.
help:describe
Description: Displays a list of the attributes for a Maven Plugin and/or
goals (aka Mojo - Maven plain Old Java Object).
help:effective-pom
Description: Displays the effective POM as an XML for this build, with the
active profiles factored in.
help:effective-settings
Description: Displays the calculated settings as XML for this project,
given any profile enhancement and the inheritance of the global settings
into the user-level settings.
help:evaluate
Description: Evaluates Maven expressions given by the user in an
interactive mode.
help:expressions
Description: Displays the supported Plugin expressions used by Maven.
help:help
Description: Display help information on maven-help-plugin.
Call mvn help:help -Ddetail=true -Dgoal=<goal-name> to display parameter
details.
help:system
Description: Displays a list of the platform details like system properties
and environment variables.
For more information, run ‘mvn help:describe [...] -Ddetail‘
====================================
3.1 描述某插件指定版本的信息:
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:3.1
====================================
Name: Maven Compiler Plugin
Description: The Compiler Plugin is used to compile the sources of your
project.
Group Id: org.apache.maven.plugins
Artifact Id: maven-compiler-plugin
Version: 3.1
Goal Prefix: compiler
This plugin has 3 goals:
compiler:compile
Description: Compiles application sources
compiler:help
Description: Display help information on maven-compiler-plugin.
Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display
parameter details.
compiler:testCompile
Description: Compiles application test sources.
====================================
3.2 描述某插件最新版本的的信息-省略版本信息
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin
3.3 通过goal prefix目标前缀描述某插件
mvn help:describe -Dplugin=compiler
3.4 通过goal prefix目标前缀 + goal目标描述某插件
mvn help:describe -Dplugin=compiler -Dgoal=testCompile
3.5 输出插件详细信息
mvn help:describe -Dplugin=compiler -Ddetail