8

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.basedir']=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?

Igor Nikolaev
  • 4,597
  • 1
  • 19
  • 19

2 Answers2

2

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)
ZeAL0T
  • 709
  • 1
  • 12
  • 27
0
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.

Dónal
  • 185,044
  • 174
  • 569
  • 824
  • This is not the case, I can see string changed in the output. The point is that when I write **print ${module.basedir}** I still get original value. – Igor Nikolaev Dec 07 '10 at 06:55