我有一组项目,他们都需要在构建期间运行相同系列的Maven插件执行.我想避免在每个项目中重新声明所有这些配置,因此我将它们全部继承自父pom"模板"项目,该项目仅包含那些插件执行(8种不同的mojos).但我希望这些插件执行只在子项目上运行,而不是在Maven构建期间在父项目上运行.
我试图完成这四种不同的方式,每种方式都有我不喜欢的副作用.
在父pom的build/plugins
元素中声明插件执行,并使用properties-maven-plugin 打开skip
父项目中其他插件的属性.这不起作用,因为其中一个插件目标(maven-dependency-plugin:build-classpath)没有skip
属性.
在父pom的build/pluginManagement
元素中声明插件执行.不幸的是,这需要我重新声明每个build/plugins
子项目的元素中的八个插件中的每个插件:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)
这太重复了,如果我需要更改模板pom中的插件,则会出现问题.
声明插件处决中被激活父POM的轮廓缺乏一个的nobuild.txt
文件(它的父POM存在,所以插件不执行有):
<profiles>
<profile>
<activation>
<file>
<missing>nobuild.txt</missing>
</file>
</activation>
<build>
....
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下都有效,除了missing
元素中的文件路径似乎基于当前工作目录而不是基于项目的工作目录.这打破了我希望能够做的一些多模块构建. 编辑:为了澄清,父"模板"项目实际上本身就是一个多模块项目中的模块,当我尝试例如mvn install
在根上执行时,构建就会中断.项目结构如下:
+ job
|- job-core
|- job-template
|- job1 inherits from job-template
|- job2 inherits from job-template
Run Code Online (Sandbox Code Playgroud)设置自定义生命周期和包装.这似乎允许我将插件绑定到生命周期阶段,但不指定任何配置.
那么,是否有另一种方法可以指定一堆Maven插件执行,这些执行可以在多个项目中重复使用(每个项目的poms中重复次数最少)?
我想在我的父pom的pluginManagement中为插件定义不同的执行,然后将特定的执行绑定到子poms中的阶段.我看到不一致的行为取决于使用的插件和pluginManagement部分的位置.
在第一个示例中,pluginManagement位于父pom中,为编译器插件定义了2个执行,为antrun插件定义了2个执行.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<name>master-pom</name>
<modelVersion>4.0.0</modelVersion>
<groupId>plugin.test</groupId>
<artifactId>master-pom</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execution-1</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 1"/>
</target>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 1"/> …
Run Code Online (Sandbox Code Playgroud) 我有一个带有父POM和三个子项目的项目.我想执行目标程序集:仅在一个子POM上进行程序集.我已经阅读了以下帖子,但我没有让它与maven程序集插件一起工作.
如果我跑
mvn -DskipTests=true assembly:assembly
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[错误]无法执行目标org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:程序内部的程序集(default-cli):读取程序集时出错:找不到程序集描述符. - > [帮助1]
它似乎总是解析插件配置并查找程序集描述符,即使这样,如果我根本没有将插件放入父POM中.谁有解决方案的组装插件?