为什么我的目标没有被执行? [英] Why is my target not getting executed?

查看:170
本文介绍了为什么我的目标没有被执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备进行部署,因此我想将正确的配置文件复制到WEB-INF/classes/ 之前,然后将所有内容打包到WAR文件中,以进行部署开发.

I am trying to get ready for deployment and therefore I want to copy the correct configuration files to WEB-INF/classes/ before everything gets packed into the WAR file for either deployment or development.

最后,我想在每次致电时执行部署任务

In the end I want to execute deployment-tasks whenever I call

mvn glcoud:deploy

-当我需要部署配置文件时,以及在我的项目目录中执行其他任何操作时,都需要开发任务.

- which is when I need deployment configuration files - and development-tasks whenever something else gets executed in my project directory.

目前,我还没有决定要怎么做,但是首先,我尝试执行这样的虚拟任务".不幸的是,它不起作用.

At the moment I have not decided how exactly I'm going to do it but first of all I try to execute such a "dummy task". Unfortunately it is not working.

这是我在pom.xml中配置的配置文件:

This is the profile I configured in the 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阶段执行此操作,这意味着

It is supposed to echo "Hello World!" and copy a x.xml file from A to B. I decided to do this in the compile phase which means

mvn clean compile

实际上应该足以执行target,但是..如果可行,我就不会在这里.

should actually be enough to get the target executed but .. I wouldn't be here if it worked.

问题:有人知道为什么没有执行该问题吗?

Question: Does somebody know why this is not getting executed?

如评论中所述,我可以/应该从build中删除pluginManagement.但是,这会给我一个错误信息:

As mentioned in a comment, I could/should remove pluginManagement from build. However, this would give me an error saying:

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: compile, phase: compile)

根据问题的答案" Spring Data Maven Builds的生命周期配置未涵盖的插件执行".

以下解决方案给出了相同的"生命周期配置未涵盖的插件执行"错误

The solution below is giving the same "Plugin execution not covered by lifecycle configuration" error

<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>

推荐答案

为了使m2e满意并能够满足您的要求,请尝试以下操作:

In order to make m2e happy and yet being able to meet your requirements, try the following:

<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> 
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
        </plugin>
    </plugins>
</build>    

请注意附加的plugins部分,该部分基本上只是重复插件的artifactId.

Note the additional plugins section which is basically just repeating the artifactId of the plugin.

这是怎么回事:

  • 通过pluginManagement部分,我们告诉Maven:每当构建(通过POM配置或命令行执行)需要执行此插件时,默认情况下应用此版本,并执行此配置
  • 然后,Maven和Eclipse之间的m2e不太完美的集成将对此插件配置感到高兴,但是除非我们有效地声明它,否则插件执行将永远不会发生
  • 通过plugins部分,我们最终真正地定义了我们的构建,告诉Maven将这个插件添加到其构建计划中.无需指定版本,配置或执行,因为我们已经将它们定义为pluginManagement(即插件管理),它将被用作默认配置/行为.
  • Via the pluginManagement section we are telling Maven: whenever the build (via POM configuration or command line execution) needs to execute this plugin, then apply this version by default and this configuration an executions
  • The m2e not-so-perfect integration between Maven and Eclipse will then be happy about this plugin configuration, however no plugin execution will ever happen unless we effectively declare it
  • Via the plugins section we are eventually really defining our build, telling Maven to add this plugin to its build plan. No need to specify version, configuration or executions, since we already defined them into the pluginManagement (that is, management of plugins), which will be applied as default configuration/behavior.

有关插件和pluginManagement之间区别的更多详细信息,请查看SO上的参考文章:Maven:是pluginManagement .

For further details concerning the difference between plugins and pluginManagement, check the reference post on SO: Maven: what is pluginManagement.

有关执行此命令的关联phase的更多说明:prepare-package阶段比compile更具选择(在语义上正确且易于维护).检查正式的构建生命周期阶段列表更多细节.关于prepare-package:

Further note on the associated phase for such an execution: the prepare-package phase would be a more (semantically correct and maintenability-friendly) choice than compile. Check the official Build Lifecycle phases list for more details. Concerning prepare-package:

在实际包装之前执行准备包装所需的任何操作.

perform any operations necessary to prepare a package before the actual packaging.


更新
看来,不仅如上所述,prepare-package阶段是一个更好的选择,而且在这种情况下,使m2e插件完全满意也是正确的阶段.


Update
It appears that not only as described above the prepare-package phase would be a better choice, but it also the right phase to make the m2e plugin perfectly happy in this case.

这篇关于为什么我的目标没有被执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆