2

我正在尝试使用 maven-replacer-plugin 替换多个文件中的值。

首先是我已经阅读了这个主题并且没有任何答案适合我。我没有足够的评论点,也没有时间也没有意愿在 SOF 上愚蠢地刷分。所以,很抱歉这个重复,但我需要向前迈进。

回到正题,这是我的pom

       <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.1</version><!-- already tried with 1.5.2 & 1.5.3 -->
            <configuration>
                <includes>
                    <include>${basedir}/target/mailtools.properties</include> 
                    <include>${basedir}/target/digishop-config.properties</include>
                </includes>

                <replacements>
                    <replacement>
                        <token>$${dev.varA}</token>
                        <value>something</value>
                    </replacement>
                    <replacement>
                        <token>$${dev.varB}</token>
                        <value>somethingElse</value>
                    </replacement>
                    <replacement>
                        <token>${dev.</token>
                        <value>${</value>
                    </replacement>
                </replacements>
                <regex>false</regex>
            </configuration>
        </plugin>

mvn替换器:替换

[INFO] --- replacer:1.5.1:replace (default-cli) @ digishop-a --- [INFO] 在 0 文件上运行替换。

我尝试了解决方案

<filesToInclude>${basedir}/target/mailtools.properties,${basedir}/target/digishop-config.properties</filesToInclude>

它也没有工作。

4

2 回答 2

1

basedir在添加尽可能多的包含之前使用,例如

<basedir>${basedir}/target</basedir>
<includes>
    <include>mailtools.properties</include>
    <include>digishop-config.properties</include>
</includes>
于 2017-03-14T17:01:46.213 回答
1

我设法通过对插件进行多次“单一替换”执行来解决这个问题

<plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>replace-xxx.properties</id>
                    <phase>install</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <file>target/xxx.properties</file>
                        <replacements>
                            <replacement>
                                <token>$${dev.mail.server.address}</token>
                                <value>xxx</value>
                            </replacement>
                            <replacement>
                                <token>$${dev.mail.server.port}</token>
                                <value>yyyy</value>
                            </replacement>
                            <replacement>
                                <token>${dev.</token>
                                <value>${</value>
                            </replacement>
                        </replacements>
                        <regex>false</regex>
                    </configuration>
                </execution>
                <execution>
                    <id>replace-zzz-config.properties</id>
                    <phase>install</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <file>target/zzz-config.properties</file>
                        <replacements>
                            <replacement>
                                <token>$${dev.hazelcast.client.group.name}</token>
                                <value>ttt</value>
                            </replacement>
                            <replacement>
                                <token>${dev.</token>
                                <value>${</value>
                            </replacement>
                        </replacements>
                        <regex>false</regex>
                    </configuration>
                </execution>
                <execution>
                    <id>replace-aaa-security.properties</id>
                    <phase>install</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <file>target/aaa-security.properties</file>
                        <replacements>
                            <replacement>
                                <token>${dev.</token>
                                <value>${</value>
                            </replacement>
                        </replacements>
                        <regex>false</regex>
                    </configuration>
                </execution>
            </executions>
        </plugin>
于 2017-02-22T09:40:27.920 回答