Maven Resources Not Copying Files

Maven by default copies all files in "src/main/resources" to the output folder, so in your current configuration it would probably create "dev", "test" and "prod" folders with their contents and then additionally copy the development resources without a "dev" prefix.

I would suggest to leave the default resources folder as it is and use it only for profile-independent resources. In your profile you can then configure additional resource folders:

<profile>
    <id>dev</id>
    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources-dev</directory>
            </resource>
        </resources>
    </build>
</profile>

It should also be possible to configure this in the common build section using properties defined in the profiles:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources-${projectStage}</directory>
        </resource>
    </resources>
</build>
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <projectStage>dev</projectStage>
        </properties>
    </profile>
</profiles>

If you for some reason can't change your current directory structure then you would have to configure exclusions for the default resource folder to not copy the nested profile-dependant folders:

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>dev/**</exclude>
                    <exclude>test/**</exclude>
                    <exclude>prod/**</exclude>
                </excludes>
            </resource>
        </resources>
    </build>

The "main" part in the maven directory structure exists for this purpose. Instead of creating directories inside the resource dir, you should create more dirs in your src directory. This is the default behavior, and it's already implemented by letting test resources override main resources during the test phases of the maven lifecycle.

Your structure should look like this:

src
  main
    resources
      a.properties
      b.properties
      c.properties
  test
    resources
      b.properties
      c.properties
  dev
    resources
      b.properties

With this structure, your "main" target will have the default property files, the test phases would temporarily overwrite b and c, and the dev profile will only overwrite b with yet another custom version, in the final deployable.

In order to achieve this, you'd have to configure the maven-resources-plugin the way you already do in our question, for a dev profile.

And when you do, also consider: what version of property files should you use when running unit tests while building using the dev profile?

Tags:

Maven 2