pom.xml中配置plugin补充
来源:互联网 发布:金盏花洁面啫喱知乎 编辑:程序博客网 时间:2024/05/19 03:20
根据《Maven的Build过程》中所述,配置plugin的时候有一个原则需要遵守:
一个Phase上至多绑定一个Goal。
那如果现在想增加一个新的Goal到项目中,该如何处理呢?
有两种方案:
一、将新的Goal绑定到还未绑定Goal的Phase上
比如default这个Lifecycle中的“validate,initialize,generate-sources,process-sources,generate-resources”等Phase默认没有绑定任何Goal,可以将新的Goal绑定到这些Phase中的任意一个上
二、通过命令行直接调用Goal的形式
比如:mvn dependency:copy-dependencies
就是直接调用"maven-dependency-plugin"这个Plugin提供的"copy-dependencies"这个Goal
采用以上两种方案在pom.xml中的配置有异同点:
1、相同点
1)两种方案都需要在pom.xml中配置提供Goal的Plugin,因为由Plugin提供Goal
2)在配置<plugin>标签时,对于其下的<groupId>,<artifactId>,<version>,<extensions>,<dependencies>,<inherited>,<configuration>子标签的配置两者都一样
2、不相同点
两者的唯一不同之处在于:
前者方案必须要在<plugin>标签下至少配置一个<executions>子标签,并且要在<executions>子标签下至少配置一个<execution>子标签,在该子标签中绑定Phase和Goal的关系
比如"mvn clean process-classes"
比如"mvn clean compile assembly:single"
一个Phase上至多绑定一个Goal。
那如果现在想增加一个新的Goal到项目中,该如何处理呢?
有两种方案:
一、将新的Goal绑定到还未绑定Goal的Phase上
比如default这个Lifecycle中的“validate,initialize,generate-sources,process-sources,generate-resources”等Phase默认没有绑定任何Goal,可以将新的Goal绑定到这些Phase中的任意一个上
二、通过命令行直接调用Goal的形式
比如:mvn dependency:copy-dependencies
就是直接调用"maven-dependency-plugin"这个Plugin提供的"copy-dependencies"这个Goal
采用以上两种方案在pom.xml中的配置有异同点:
1、相同点
1)两种方案都需要在pom.xml中配置提供Goal的Plugin,因为由Plugin提供Goal
2)在配置<plugin>标签时,对于其下的<groupId>,<artifactId>,<version>,<extensions>,<dependencies>,<inherited>,<configuration>子标签的配置两者都一样
2、不相同点
两者的唯一不同之处在于:
前者方案必须要在<plugin>标签下至少配置一个<executions>子标签,并且要在<executions>子标签下至少配置一个<execution>子标签,在该子标签中绑定Phase和Goal的关系
后者方案无需配置<plugin>下的<executions>子标签,配置了也不会产生效果,因为我们通过在命令行直接调用的形式来执行Goal
举例说明,现在想往项目中添加“assembly:single”这个Goal,有两种方案:
1、绑定新Goal到"process-classes"这个Phase
由于default这个Lifecycle中的"process-classes"这个Phase默认未绑定任何Goal,因而可以将新Goal绑定到该Phase上
pom.xml中的配置片段如下:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>default-single</id> <phase>process-classes</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <archive> <manifest> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration></plugin>现在想执行新Goal,只需要调用default这个Lifecycle中的"process-classes"或者其后的Phase
比如"mvn clean process-classes"
2、在命令行中直接调用新Goal
pom.xml中的配置片段如下:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>fully.qualified.MainClass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration></plugin>现在想执行新Goal,直接在命令行中调用
比如"mvn clean compile assembly:single"
0 0
- pom.xml中配置plugin补充
- pom.xml中配置plugin
- pom.xml中maven-compiler-plugin插件配置的使用
- tomcat-maven-plugin在pom.xml中的配置
- pom.xml中maven-compiler-plugin报错
- maven中 pom.xml中配置详解
- maven中pom.xml配置详解
- maven中pom.xml常用配置
- maven中pom.xml配置说明
- SSM中pom.xml文件的配置
- pom.xml配置
- pom.xml配置说明
- pom.xml配置
- pom.xml配置
- pom.xml 配置详解
- pom.xml配置初步
- pom.xml 配置
- Maven pom.xml配置
- android 语音识别
- Java--内部类,局部类与匿名类
- linux上寻找并杀死僵尸进程
- 黑马程序员——Java Collection集合
- tiff文件读取若干问题
- pom.xml中配置plugin补充
- 学习网站博客
- iOS即时通讯
- eclipse tomcat May be locked by another process 解决
- 关于coalesce的一些经验记录【陆续增补】
- iOS音乐后台播放及锁屏信息显示
- Circular dependencies cannot exist in RelativeLayout错误解决
- LeetCode(109) Convert Sorted List to Binary Search Tree
- AR增强现实摄像机拍照功能(部分)