Maven 2 Maven2-插件管理和父子关系问题
来自maven pluginManagement:是一个可以在插件旁边看到的元素。插件管理包含插件元素的方式与此基本相同,不同之处在于它不是为这个特定的项目构建配置插件信息,而是配置从这个项目构建继承的项目构建。但是,这仅配置在子元素的plugins元素中实际引用的插件。孩子们完全有权推翻插件管理的定义 现在:如果我的父母POM中有这个Maven 2 Maven2-插件管理和父子关系问题,maven-2,Maven 2,来自maven pluginManagement:是一个可以在插件旁边看到的元素。插件管理包含插件元素的方式与此基本相同,不同之处在于它不是为这个特定的项目构建配置插件信息,而是配置从这个项目构建继承的项目构建。但是,这仅配置在子元素的plugins元素中实际引用的插件。孩子们完全有权推翻插件管理的定义 现在:如果我的父母POM中有这个 <build> <pluginManagement> <plugins> <pl
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<executions>
Some stuff for the children
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
maven依赖插件
2
给孩子们的东西
我在父项目上运行mvn help:effectivepom,我得到了我想要的东西,即直接构建的插件部分(执行工作的部分)仍然是空的
现在,如果我执行以下操作:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<executions>
Some stuff for the children
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
maven依赖插件
2
给孩子们的东西
maven编译器插件
2.0.2
真的
1.6
1.6
mvn帮助:有效的pom我再次得到我想要的,插件包含声明的内容,插件管理部分被忽略
但是随着下面的变化
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<executions>
Some stuff for the children
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<inherited>false</inherited> <!-- this perticular config is NOT for kids... for parent only -->
<executions>
some stuff for adults only
</execution>
</executions>
</plugin>
</plugins>
</build>
maven依赖插件
2
给孩子们的东西
maven依赖插件
2
假的
有些东西是成人专用的
并运行mvn帮助:有效的pom
pluginManagement部分的内容被添加到已经声明的内容之上。因此:
<build>
<pluginManagement>
...
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<inherited>false</inherited> <!-- this perticular config is NOT for kids... for parent only -->
<executions>
Some stuff for the children
</execution>
<executions>
some stuff for adults only
</execution>
</executions>
</plugin>
</plugins>
</build>
...
maven依赖插件
2
假的
给孩子们的东西
有些东西是成人专用的
是否有办法将子零件从父pom部分中排除?实际上,我希望pluginManagement的行为完全符合文档中的说明,也就是说,我希望它只适用于子项,而不适用于声明它的项目
作为一个佐证,有没有一种方法可以通过在项目的正常构建部分声明插件来覆盖pluginManagement中的部分?无论我尝试什么,我都会发现该部分被添加到执行中,但我无法覆盖已经存在的部分。
编辑:
我从来没有找到一个可以接受的解决方案,因此这个问题仍然悬而未决。下面提供了最接近的解决方案,在出现更好的解决方案之前,该解决方案目前是该问题的公认解决方案。现在有三种方法可以达到预期的结果(根据当前POM在继承层次结构中的位置调整插件行为):
1-使用配置文件,它会起作用,但您必须注意,配置文件不是继承的,这有点违反直觉。它们(如果激活)应用于声明的POM,然后生成的POM向下传播。因此,激活子POM的概要文件的唯一方法是在命令行上(至少我没有找到其他方法)。属性、文件和其他激活方式无法激活POM,因为触发器不在声明概要文件的POM中
2-(这就是我最后要做的)声明插件在父级中没有继承,并在每个需要它的子级中重新声明(复制粘贴)消息。虽然不理想,但它很简单而且有效
3-拆分父POM的聚合性质和父性质。然后,由于只适用于父级的部分位于不同的项目中,现在可以按照最初的意图使用pluginManagement。然而,这意味着必须创建一个新的人工项目,该项目不对最终产品做出贡献,而只为系统服务。这是明显的概念性出血。此外,这只适用于我的具体情况,很难概括,所以我放弃了努力,并使这项工作,以支持不漂亮,但更包含剪切和粘贴补丁描述在2
如果有人遇到这个问题有更好的解决方案,或者是因为我缺乏Maven的知识,或者是因为工具的发展允许这样做,请在这里发布解决方案以供将来参考
谢谢大家的帮助:-)将插件配置添加到pluginManagement意味着如果声明了插件,将使用此配置,但是您仍然需要在任何想要使用它的POM的build部分声明插件 从您引用的章节中可以解释这一点的关键部分是: 但是,这仅配置在子元素的plugins元素中实际引用的插件 因此,如果在子pom中执行此操作,将应用来自父pom的配置:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
maven依赖插件
更新:为了回答实际问题,pluginManagement部分的内容总是与任何插件声明合并。为了避免父项目这样做,您可以在概要文件中定义pluginManagement部分,并在子项目上激活该概要文件,但不能在父项目上激活该概要文件。然后子项目必须声明该概要文件
例如:
<profiles>
<profile>
<id>for-children</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<executions>
<!--Some stuff for the children-->
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
<inherited>false</inherited> <!-- this perticular config is NOT for kids... for parent only -->
<!--some stuff for adults only-->
</executions>
</plugin>
</plugins>
</build>
儿童
maven依赖插件
2
maven依赖插件
2
假的
您必须为执行分配一个ID,以便maven
<plugin>
<artifactId>some-plugin</artifactId>
<executions>
<execution>
<id>execution-id</id>
<phase>partcular-phase</phase>
</execution>
</executions>
</plugin>
<execution>
<id>execution-id</id>
<goals><goal>some-goal</goal></goals>
<phase>none</phase>
</execution>