Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - resource filtering : implications of the @ symbol in resource files

I am using the Maven assembly plugin to prepare some configuration artifacts for different environments, and I am using resource filtering to substitute parameter values.

I came across a weird behaviour where I had a property file with the contents as follows:


###########################

# [email protected] #

############################

env.name=${replacement.value}


The presence of the '@' symbol for the author's e-mail was causing all property references to be ignored.

I have tried looking for documentation as to why this happens - but cannot find anything that answers this behaviour. Any helpful pointers to documention or an explanation would be much appreciated.

For reference:

  1. Maven version: 2.2.1
  2. Maven Assembly Plugin version: 2.2
like image 803
Dinuk Avatar asked Oct 29 '10 21:10

Dinuk


People also ask

What is resource filtering in Maven?

Resource Filtering. You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for property references surrounded by ${ and }.

What is the use of resources tag in POM XML?

Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.

What is resource directory in Maven?

Overview With the default Maven layout, we store resource files under the src/main/resources directory. After a build, Maven moves these files to the build output directory - target/classes. So they become available in the application classpath. There are cases where we have resource files under different directories.


2 Answers

I have tried looking for documentation as to why this happens - but cannot find anything that answers this behaviour. Any helpful pointers to documentation or an explanation would be much appreciated.

This is not documented in the filtering section of the Maven Assembly Plugin but it looks like it uses the same default delimiters as the Maven Resources Plugin which are:

<build>
  ...
  <plugin>
    ...
    <configuration>
      ...
      <delimiters>
        <delimiter>${*}</delimiter>
        <delimiter>@</delimiter>
      </delimiters>

So the following would be filtered as well:

[email protected]@

And this also explains why a single @ in the email address is causing troubles (the plugin never finds the end delimiter).

It is possible to configure the delimiters and an escape string, just as it is when using the Maven Resources Plugin. The Maven Assembly Plugin documentation for the single goal provides the details.

A cheap workaround, for this particular email address situation, would be to avoid using a single @ in the file to filter:

##############################
# author.name aT company.com #
##############################

env.name=${replacement.value}

And as a benefit, you'll avoid spam :)

like image 124
Pascal Thivent Avatar answered Jan 02 '23 10:01

Pascal Thivent


You should specify the plugin explicitly in your pom.xml. Implicitly, it is using 2.4.1, which has this issue. You can verify which version maven is using by running maven -X resources:resources.

Version 2.6 fixed this problem.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
</plugin>
like image 25
cwu9T9 Avatar answered Jan 02 '23 10:01

cwu9T9