0

I need to rename set of files in maven without using Maven-Antrun-plugin in a single execution or command.

I have many property files with same suffix ab_bc.properties,de_bc.properties,etc and I need to replace the suffix to some other name like ab_BR.properties,de_BR.properties.

Is there any plugin available to do the same in Maven?

I tried Maven-assmbly plugin and copy-rename plugin but adding lot of files makes it more complex.

2 Answers2

1

You can give this plugin a try or have a look on workarounds with the Maven Assembly plugin, see related question here.

Hope that helps :)

Community
  • 1
  • 1
javapapo
  • 1,342
  • 14
  • 26
  • Thanks for the info.However I need to do in a more generic way using some patterns rather than specifying each filename in the pom or descriptor which is a tedious job. :( – Mohamed Thoufeeque Jan 05 '16 at 10:07
  • I am afraid either the proposed plugin in my answer above or an Ant task and then invocation of the Maven Ant plugin - are your best options. :/ – javapapo Jan 05 '16 at 15:12
0

You can use maven-antrun-plugin, here is an example:

in pom.xml file:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>prepare-flyway-migration-files</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <ant antfile="build.xml">
                                    <target name="prepareFlywayMigrationFiles"/>
                                </ant>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

in build.xml:

<project name="demo" default="dist" basedir=".">
    <description>Prepare flyway migration files</description>

    <target name="prepareFlywayMigrationFiles">
        <!-- You can also use `move` instead `copy` task to do the inplace renaming. -->
        <copy todir="target/migration">
            <fileset dir="ddl"/>
            <regexpmapper from="^v(\d+)\.(\d+)\.(\d+)-(.*)\.sql" to="V\1_\2_\3__\4.sql"/>
        </copy>
    </target>
</project>

See ant Mapping File Names for more information.

hyc
  • 1
  • 1