5

我想使用 maven-replacer-plugin 将文件中的 $file-list$ 替换为项目文件夹中以逗号分隔的文件列表。这可能吗?

谢谢

4

1 回答 1

13

这是我所做的:

使用 antrun 插件创建一个包含列表的临时文件:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <configuration>
                <target>
                    <fileset id="my-fileset" dir="src/main/resources" />
                    <pathconvert targetos="unix" pathsep=","
                        property="my-file-list" refid="my-fileset">
                        <map from="${basedir}\src\main\resources\" to="" />
                    </pathconvert>
                    <echo file="${basedir}\target\file-list.txt">${my-file-list}</echo>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

然后使用替换插件替换我想要的文件中的列表:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <executions>
        <execution>
            <id>replace-file-list</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>replace</goal>
            </goals>
            <configuration>
                <ignoreMissingFile>false</ignoreMissingFile>
                <file>target/MY_FILE.TXT</file>
                <regex>false</regex>
                <token>$file-list$</token>
                <valueFile>target/file-list.txt</valueFile>
            </configuration>
        </execution>
    </executions>
</plugin>

我相信一定有更好的方法,但希望这对某人有所帮助。

于 2012-12-05T18:27:46.227 回答