being_ethereal
being_ethereal

Reputation: 885

How to remove comments from properties file using maven build?

Suppose I have following in my properties file

#production db
db.url=com.some.prod.url
db.port=4565

#development db
#db.url=com.some.dev.url
#db.port=4577

After the build finishes, I want my properties file clean of all commented properties in the build file. So, final outcome becomes:

db.url=com.some.prod.url
db.port=4565

Upvotes: 2

Views: 831

Answers (2)

being_ethereal
being_ethereal

Reputation: 885

Figured it out finally. Used maven-replacer-plugin, and replaced a regex of <new line><hash><any set of characters> i.e. \r\n#(.*) with <blank>

Update: in order to be able to execute this on jenkins(linux instance, in my case), have added a pattern \n#(.*)

       <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>target/**/*.properties</include>
                </includes>
                <commentsEnabled>false</commentsEnabled>
                <regex>true</regex>
                <replacements>
                    <replacement>
                        <token>\r\n#(.*)</token>
                        <value></value>
                    </replacement>
                    <!-- Following line was added in update(linux compatible) -->
                    <replacement>
                        <token>\n#(.*)</token>
                        <value></value>
                    </replacement>
                </replacements>
            </configuration>
        </plugin>

Upvotes: 2

You can try Maven Antrun Plugin and ant task replaceregexp

Upvotes: 0

Related Questions