【发布时间】:2016-06-02 20:43:49
【问题描述】:
我正在尝试为部署做好准备,因此我想将正确的配置文件复制到WEB-INF/classes/在所有内容都打包到 WAR 文件中以供 部署或开发。
最后我想在调用时执行部署任务
mvn glcoud:deploy
- 这是我需要部署配置文件的时候 - 以及每当在我的项目目录中执行其他内容时的开发任务。
目前我还没有决定我将如何做,但首先我尝试执行这样一个“虚拟任务”。不幸的是,它不起作用。
这是我在pom.xml中配置的配置文件:
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<echo message="Hello World!"/>
<copy file="src/main/resource/x.xml" todir="src/main" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
应该是echo“Hello World!”并将 x.xml 文件从 A 复制到 B。我决定在 compile 阶段执行此操作,这意味着
mvn clean compile
实际上应该足以让target 被执行,但是.. 如果它有效,我就不会在这里。
问题:有人知道为什么没有执行吗?
正如评论中提到的,我可以/应该从build 中删除pluginManagement。但是,这会给我一个错误提示:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: compile, phase: compile)
我根据问题“How to solve “Plugin execution not covered by lifecycle configuration” for Spring Data Maven Builds”的答案添加了pluginManagement。
下面的解决方案是给出相同的“生命周期配置未涵盖插件执行”错误
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<!-- -->
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
我也看到了同样的情况:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<!-- -->
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profiles>
【问题讨论】:
-
移除
<pluginManagement>元素,即放入build/plugins而不是build/pluginManagement部分。 -
@A.DiMatteo 我不得不添加它,因为否则 m2e 会识别另一个 question 中描述的错误。
-
啊,评论太长了,我需要写一个答案.. ok
-
@A.DiMatteo 期待它:D
-
除上述内容外,您永远不应该复制(不管如何)到
src/,因为它受版本控制。此外,您正在做的是从src/main/resources/复制,默认情况下由资源复制处理...所以无需添加maven-antrun-plugin...
标签: maven m2e maven-antrun-plugin