Alex, You are correct my "fix" was pretty cryptic. When I wrote it I was not entirely sure why what I did corrected the issue. You are right the fundamental issue has to do with when the string interpolation happens. If it is done by maven then groovy is left with a literal string containing unescaped characters. There are several ways this can be resolved, you point out a few. The approach I took was to provide a property which gets treated as a groovy variable rather than a string literal in the provided script.
On Thu, Jan 6, 2022 at 8:00 PM Alexander Kriegisch <alexan...@kriegisch.name> wrote: > Fred, > > you did not describe how exactly you solved the problem. You just > mentioned properties of which there are several types, which is why your > answer is unclear: > -- literal Maven properties which you tried to use before > -- '<properties>' for the GMplus 'execute' goal > -- properties implicitly bound inside GMPlus scripts > > Using the latter, you could just directly use 'project.basedir' (which > yields a File instance already) and the corresponding File constructor: > > new File(project.basedir, > "src/main/javascript/gremlin-javascript/package.json") > > Of if you do want to use the File(String) constructor: > > new > File("$project.basedir/src/main/javascript/gremlin-javascript/package.json") > > Probably you meant something like this, but let us close this thready > with an explicit answer, just for reference. > > As for why the "${project.basedir}" syntax yields problems inside the > Groovy script: It is because Maven already expands the expression, so > the Groovy parser sees an illegal string literal with single, unescaped > backslash characters. You can see this on the console when running your > Maven build with debug output. > > -- > Alexander Kriegisch > https://scrum-master.de > > > Fred Eisele schrieb am 07.01.2022 07:37 (GMT +07:00): > > > I found the fix. > > I need to use > > https://github.com/groovy/GMavenPlus/wiki/Examples#execute-scripts > > properties which somehow do not have this problem. > > > > On Thu, Jan 6, 2022 at 6:13 PM Fred Eisele <fredrick.eis...@gmail.com> > > wrote: > > > >> > >> I have a situation where I am using a code generator which reads text > >> generated from the pom.xml file. > >> The problem is that the code generator is written in groovy which does > not > >> like '\' in the file path. > >> The current line of code is... > >> ```maven > >> def file = new File("${project.basedir}/src/main/javascript/gremlin- > >> javascript/package.json") > >> > >> ``` > >> which gets converted and processed by the groovy based generator > resulting > >> in... > >> ```text > >> Script1.groovy: 3: unexpected char: '\' @ line 3, column 24. > >> def file = new > >> > File("C:\Users\me\tp-x\gremlin-javascript/src/main/javascript/gremlin-javascript/package.json") > >> ``` > >> This is part of an Apache open source > >> project. > https://github.com/apache/tinkerpop/blob/53503bfa28ba1de061204fb96835dee856576bbf/gremlin-javascript/pom.xml#L126I > >> want to know how to best manipulate the project.basedir value so as not > to > >> have a path that groovy does not like. > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > >