【问题标题】:Maven-replacer-plugin is not invoked with maven-war-pluginMaven-replacer-plugin 不使用 maven-war-plugin 调用
【发布时间】:2016-08-29 11:52:27
【问题描述】:

我正在尝试使用 maven 将字符串 %APP_NAME% 替换为 jdbc.properties 中的环境变量。我有以下配置:

<pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.google.code.maven-replacer-plugin</groupId>
                    <artifactId>replacer</artifactId>
                    <version>1.5.2</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>replace</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <basedir>${project.build.directory}/classes</basedir>
                        <includes>
                            <include>jdbc.properties</include>
                        </includes>
                        <replacements>
                            <replacement>
                                <token>%APP_NAME%</token>
                                <value>${env.BRANCH_NAME}</value>
                            </replacement>
                        </replacements>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                    <executions>
                        <execution>
                            <!-- First step is to disable the default-war build step. -->
                            <id>default-war</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <!-- Second step is to create an exploded war. Done in prepare-package -->
                            <id>war-exploded</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>exploded</goal>
                            </goals>
                        </execution>
                        <execution>
                            <!-- Last step is to make sure that the war is built in the package 
                                phase -->
                            <id>custom-war</id>
                            <phase>package</phase>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <additionalProjectnatures>
                            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        </additionalProjectnatures>
                        <additionalBuildcommands>
                            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                        </additionalBuildcommands>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <!-- <compilerArgument>-Xlint:all</compilerArgument> -->
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                        <compilerArguments>
                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                        </compilerArguments>
                    </configuration>
                </plugin>   
        </plugins>
</pluginManagement>

当我调用时:

mvn clean package

mvn clean install

没有调用替换插件。谁能解释一下为什么以及我该怎么做才能让它发挥作用?或者,如果替换器与未来的战争插件不兼容,任何人都可以在构建战争之前向我解释在 jdbc.properties 中替换某些字符串的任何其他方式吗?我也看到了 ant 插件,但配置相同,它也没有被调用。下面的例子..

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version> 
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>package</phase>
            <inherited>false</inherited> 
            <configuration>
                <tasks>
                    <replace dir="${basedir}/src/main/resources">
                        <include name="**/jdbc.properties" />
                        <replacefilter token="%APP_NAME%" value="${env.BRANCH_NAME}"/>
                    </replace>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals> 
        </execution>
    </executions>
</plugin>

【问题讨论】:

标签: maven maven-war-plugin maven-antrun-plugin maven-replacer-plugin


【解决方案1】:

插件在&lt;pluginManagement&gt; 块中定义:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
...

找到需要运行替换器的 POM 的 &lt;build&gt;&lt;plugins&gt; 块,并添加以下内容:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
</plugin>

插件管理更像是一个模板,用于说明调用插件时应该发生的事情。如果&lt;build&gt;&lt;plugins&gt; 块中没有引用该插件,则不会发生任何事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 2011-02-28
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多