假设我的属性文件中有以下内容
#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
最佳答案
终于明白了。
使用过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>
关于java - 如何使用 Maven 构建从属性文件中删除注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839353/