Как удалить комментарии из файла свойств с помощью сборки maven? - PullRequest
0 голосов
/ 18 декабря 2018

Предположим, в моем файле свойств есть следующее

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

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

После завершения сборки я хочу, чтобы мой файл свойств был очищен от всех закомментированных свойств в файле сборки.Итак, окончательный результат становится:

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

Ответы [ 2 ]

0 голосов
/ 22 декабря 2018

наконец-то понял.Использовал maven-replacer-plugin и заменил регулярное выражение <new line><hash><any set of characters>, то есть \r\n#(.*) на <blank>

Обновление : чтобы можно было выполнить это на jenkins (экземпляр linux, вмой случай), добавили шаблон \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>
0 голосов
/ 18 декабря 2018

Вы можете попробовать Maven Antrun Plugin и задачу муравья replaceregexp

...