Maven:使用基于配置文件的插件 [英] Maven: Using a Plugin Based On Profile

查看:103
本文介绍了Maven:使用基于配置文件的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,该文件维护发布版本的内部版本号.每次进行发行版本构建时,此数字都会增加,并且文件会保存到svn存储库中.

现在说我有一个插件可以完成此工作,并且我已经创建了一个构建配置文件.但是我需要仅在构建配置文件被激活时才触发此插件,否则就不会.我想将pluginManagement添加到配置文件中可能是下面的方法.有什么建议吗?

 <profiles>
    <id>release</id>      
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    ..
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profiles>
 

解决方案

我建议您先看看构建配置文件的文档.您可以在此处找到.您要查看的第一件事是此部分:

如何触发个人资料?这如何根据 使用的个人资料类型?

基本上,一旦您了解了这一点,请注意,您在个人资料部分中输入的内容与您在个人资料中外部的内容非常接近.话虽这么说,如果您需要一个特定于配置文件的构建部分,它应该模拟您在配置文件之外的内容-如果您查看pom.xsd,则与我相信的完全相同. /p>

例如,

 <profiles>
    <profile>
        <id>full-build</id>
        <activation>
            <property>
                <name>build</name>
                <value>full</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo.webstart</groupId>
                    <artifactId>webstart-maven-plugin</artifactId>
                    <version>1.0-beta-1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jnlp</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <resourcesDirectory>src/main/web</resourcesDirectory>
                        ....
 

这可以通过运行以下命令来触发:mvn package -Dbuild=full

我希望这会有所帮助.

I have a file which maintains a build-number for release build. Everytime a release build is made, this number is incremented and the file is saved into svn repository.

Now say I have a plugin to do this job and i have created a build profile. But I need this plugin to be triggered only when build profile is activated and not otherwise. I guess adding pluginManagement to profile could be the way out like below. Any suggestions?

<profiles>
    <id>release</id>      
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    ..
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profiles>

解决方案

I would suggest you take a look at the documentation for build profiles first. You can find that here. The first thing you want to look over is this section:

How can a profile be triggered? How does this vary according to the type of profile being used?

Basically, once you understand that, note that what you put in your profile section is pretty close to what you have outside your profile. That being said, if you need a profile specific build section, it should emulate what you would have outside the profile - if you take a look at the pom.xsd it is the exact same I believe.

So, for example:

<profiles>
    <profile>
        <id>full-build</id>
        <activation>
            <property>
                <name>build</name>
                <value>full</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo.webstart</groupId>
                    <artifactId>webstart-maven-plugin</artifactId>
                    <version>1.0-beta-1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jnlp</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <resourcesDirectory>src/main/web</resourcesDirectory>
                        ....

This would be triggered by running: mvn package -Dbuild=full

I hope this helps.

这篇关于Maven:使用基于配置文件的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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