0


I am trying to exclude from a build all YAML resource files, but the ones with a prod clause within the filename.
For example, given that my resource directory contains application-dev.yaml, application-test.yaml and application-prod.yaml, I would like application-dev.yaml and application-test.yaml to be excluded and application-prod.yaml to be kept.

The portion of my POM that deals with the resources is below:

<build>
  <resources>
    <resource>
      <directory>${project.basedir}/src/main/resources</directory>
      <excludes>
        <exclude>**/*-!(prod).yaml</exclude>
      </excludes>
    </resource>
    <resource>
      <directory>${project.basedir}/web/WEB-INF</directory>
    </resource>
  </resources>

However, exclusion does not work and all YAML files are copied, including application-dev.yaml and application-test.yaml.
I tested the exclusion pattern in Bash shell by ls *-!(prod).yaml and it worked as expected.

At this point I am lost and am looking for the community assistance.
I thank you all in advance for your thoughts and comments.

Lev
  • 287
  • 3
  • 13
  • Have you taken a look into the documentation? https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html – khmarbaise Nov 16 '19 at 17:45
  • @khmarbaise The point is that a complex exclusion pattern does not work. If I simplify the pattern to be _*.yaml_ rather than _*-!(prod).yaml_, the exclusion works perfectly. I could have gone by excluding everything, and including the desired files - it is less elegant, because I have to mention explicitly _log4j2.xml_ and so on. I am trying to make the complex pattern to work... – Lev Nov 16 '19 at 19:54
  • 1
    Maven-resources-plugin uses ant based patterns which doesn't support '!'. – Ramu Nov 17 '19 at 07:38
  • @Ramu It was a valuable point, hence I switched to regex as Ant supports regex patterns. I changed the exclusion pattern to a regex form _^.+\-((?!prod).)*\.yaml$_, tested the pattern in Notepad++; however, Maven still does not exclude the files... – Lev Nov 17 '19 at 14:18
  • 1
    @Lev Ant does support regex patterns but the Ant's Fileset patterns only supports `*, ** and ?` and Maven resource plugin also uses the same patterns. Please refer following links for more details. [Ant Fileset](https://en.wikibooks.org/wiki/Apache_Ant/Fileset) [ DirectoryScanner used by Maven plugin](https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/DirectoryScanner.html) – Ramu Nov 17 '19 at 16:22
  • I suppose you are running a spring boot app. As a resolve I would use the other profiles only for development or tests which means they should belong to `src/test/resources` . – khmarbaise Nov 18 '19 at 07:43

1 Answers1

0

In order to solve that I would go with maven profiles and resource plugin maven resource plugin You can have variables to the resource file name according to what you need (prod, dev, etc)

Mickey Hovel
  • 982
  • 1
  • 15
  • 31