我有一个包含多个模块的父聚合器POM。我在父级中有一个build/pluginManagement
,因为每个子模块的插件执行是相同的。
如果我在每个子模块(mvn package
)中执行,它可以正常工作。如果我在父:mvn package -Pmytest
中执行,我想跳过父模块中的插件执行,所以我添加了:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
然而,它不起作用。
父pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz.jboss.config</groupId>
<artifactId>jboss-config</artifactId>
<packaging>pom</packaging>
<version>1.2-SNAPSHOT</version>
<name>jboss-config</name>
<url>http://maven.apache.org</url>
<profiles>
<profile>
<id>mytest</id>
<modules>
<module>jboss-system-properties</module>
<module>jboss-security</module>
</modules>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>process-package</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/processed/scripts</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/scripts</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>process-clean</id>
<phase>clean</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/processed/scripts</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/scripts</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-${project.artifactId}</id>
<phase>package</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<execute-commands>
<scripts>
<script>${basedir}/processed/scripts/add-${project.artifactId}.cli</script>
</scripts>
</execute-commands>
</configuration>
</execution>
<execution>
<id>remove-${project.artifactId}</id>
<phase>clean</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<execute-commands>
<scripts>
<script>${basedir}/processed/scripts/remove-${project.artifactId}.cli</script>
</scripts>
</execute-commands>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Child pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xyz.jboss.config</groupId>
<artifactId>jboss-config</artifactId>
<version>1.2-SNAPSHOT</version>
</parent>
<artifactId>jboss-system-properties</artifactId>
<packaging>ear</packaging>
<name>jboss-system-properties</name>
<url>http://maven.apache.org</url>
</project>
我收到文件未找到错误。该文件不应存在于此处。问题是为什么它不会跳过父模块执行。
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] jboss-config ....................................... FAILURE [ 20.238 s]
[INFO] jboss-system-properties ............................ SKIPPED
[INFO] jboss-security ..................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:
execute-commands (add-jboss-config) on project jboss-config:
Execution add-jboss-config of goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:execute-commands failed:
Failed to process file 'H:\projects\xyz\jboss\trunk\jboss-configuration\processed\scripts\add-jboss-config.cli':
H:\projects\xyz\jboss\trunk\jboss-configuration\processed\scripts\add-jboss-config.cli
(The system cannot find the path specified)
答案 0 :(得分:2)
我发现了这个问题。如果执行id是参数化的,在我的情况下:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-${project.artifactId}</id>
...
...
<executions>
<execution>
<id>remove-${project.artifactId}</id>
...
...
要跳过插件执行,您必须明确指定执行ID和阶段:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-jboss-config</id>
<phase/>
</execution>
<execution>
<id>remove-jboss-config</id>
<phase/>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
现在,它会跳过父项,在所有子模块中执行,而我只有一个地方可以进行插件配置。
注意:我尝试使用静态执行ID,但它也会在子模块中跳过执行的副作用。另外,我不确定所有这些问题是否只是在wildfly-maven-plugin中。