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

丶灬走出姿态 提交于 2019-11-29 03:23:15
Pascal Thivent

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:

env.name=@replacement.value@

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 :)

cwu9T9

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>

I had the same problem but I could not use Pascal's workaround as @s were part of filtered SQL scripts. So I elaborated on Pascal's solution and haven't found any way how to override default delimiters in Assembly Plugin. However, I've found another useful post (at the very bottom): http://web.archiveorange.com/archive/v/F1XzEmhzIHiBcpS0RyC6

Which suggests using a properly configured resource plugin to copy and filter problematic resources and then use these filtered resources in the assembly plugin. e.g.: (pom.xml)

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/filtered-resources/scripts</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/assemble/resources/scripts</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
                <useDefaultDelimiters>false</useDefaultDelimiters>
                <delimiters>
                    <delimiter>${*}</delimiter>
                </delimiters>
            </configuration>
        </execution>
    </executions>
</plugin>

(distribution.xml)

<fileSet>
    <directory>target/filtered-resources/scripts</directory>
...
</fileSet>

i had the same problem, i used a little workaround:

you must mantain '@' char always peer adding a fictitious variable

###########################
author.name@company.com
falsevar=@
############################

env.name=${replacement.value}
Laurent Ho

Here the link to Maven JIRA issue: https://issues.apache.org/jira/browse/MRESOURCES-141

Filtering doesn't work when there is an odd number of @ in the resource

This seriously works. Define in a properties file as follows:

@=@
emaildomain=example.com

Attempt to set-up an email address using both ${@} and just @.

domain_email=name${@}${emaildomain}
domain_email_using_at=name${@}@emaildomain@
no_domain_email=name@${emaildomain}

Results:
domain_email=name@example.com
domain_email_using_at=name@example.com
no_domain_email=name@${emaildomain}

This should get negative points as it is crazy that it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!