Search code examples
mavenmaven-archetypearchetypes

Prevent Maven from removing $ (dollar sign) from archetype resources?


I have a Maven archetype with some .java files. Inside them I perform some tests that need to use $ to evaluate json with json-path, e.g.:

.andExpect(jsonPath("$.id", is(1)))

When I generate the project with mvn archetype:generate, the dollar is no longer present:

.andExpect(jsonPath(".id", is(1)))

Is there any way to tell Maven not to remove that $?

I've tried escaping in different ways: \$ - $$ - \$...without success.

I've noticed that the $ sign is only removed when it's followed by a dot and some text:

  • $$ stays $$
  • $. stays $
  • $.text changes into .text

Solution

  • This is somewhat of a workaround, but you can do:

    .andExpect(jsonPath("$"+".id", is(1)))
    

    to prevent maven from removing it.