开发者

How to replace backslashes to slashes for ${basedir} property in maven profile profile

I have a pom.xml with defined property module.basedir that is intended to contain transformed basedir property. It is defined as follows:

<properties>
    <module.basedir>${basedir}</module.basedir>
</properties>

And I have following code that is executed using mgroovy plugin:

<source>
    println project.properties['module.basedir']
    project.properties['module.base开发者_如何学运维dir']=project.properties['module.basedir'].replace('\\','/');
    println project.properties['module.basedir']
</source>

Later I use this property in other plugins. This works fine until I move plugin definitions into maven profile. And when maven profile is activated mgroovy plugin works fine, but when I access property in the next plugin I get unmodified value.

This is how I access this property:

${module.basedir}

It looks like that when profile is executed it creates own copies of properties defined in project and they are used when referenced from plugins.

Any suggestions?


I faced with the same problem using gmaven-plugin on windows to create EJB module description. I'm not a savvy in Groovy, but this approach works for me:

def basedir = project.properties['module.basedir'].replace('\\','/')
def md = (basedir + "/target/module.xml" as File)


String path = '\\a\\b\\c'
assert path.replaceAll('\\\\', '/') == '/a/b/c'

So you need to replace this line:

project.properties['module.basedir']=project.properties['module.basedir'].replace('\\','/');

with

project.properties['module.basedir']=project.properties['module.basedir'].replace('\\\\','/');

The reason you need 4 backslashes, is because each of the double-backslashes in the source String (path in my example) must be escaped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜