0

I am trying to copy an xml file at build time using maven resource plugin with no success till now.

<profile>
.
.
<build>
.

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
    <resource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>
.
.
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
            <encoding>UTF-8</encoding>
        </configuration>
        <executions>
            <execution>
                <id>copy-resources</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/target/Test</outputDirectory>
                    <overwrite>true</overwrite>
                    <resources>
                        <resource>
                            <directory>${basedir}/target/common-aws</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>*.xml</include>
                            </includes>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>   
<plugins>
.
.
</build>
.
.
</profile>

Maven Goal - clean install

Does it need any special maven goal to get things copied ? Please help me out here.

plugin version -2.6

Refering this

Naxi
  • 1,504
  • 5
  • 33
  • 72
  • Why do you need to copy things manually? follow conventions... – khmarbaise Apr 27 '19 at 13:08
  • can you post a bigger portion of you pom file? at least, the element containing this `plugin` ? – Daniele Apr 27 '19 at 14:02
  • @khmarbaise I have two separate environments for which I need to copy different xml based upon the profile – Naxi Apr 27 '19 at 14:53
  • 1
    what exactly isn't working? Is the copy-resource goal being invoked? Do the files exist when the goal is executed? Maybe the issue is in the ordering- the files are being copies, but AFTER the jar has been packaged (in this case, you should copy-resources in a previous phase). If you enable the debug logs (`mvn clean install -X`), you should be able to see what each plugin is doing, and in what order. Anything strange there? – Daniele Apr 27 '19 at 15:27
  • @Daniele As per the logs, this execution is not getting run. There are other copy-resource goals along with this one and they are running while this one is not. I am analyzing why is this the case. Thanks for your guidance here . – Naxi Apr 27 '19 at 16:13
  • @Daniele Solved the issue. There were two maven resource plugins in the pom.xml file (I don't know why !). I was placing my configurations in the one which was not being picked. When I placed it within the another resource plugin section, all worked fine. Also, I changed phase to - process-resources – Naxi Apr 27 '19 at 17:09

1 Answers1

2

The issue was wrong phase and multiple maven-resource-plugin entries.

Below code worked for me.

<execution>
        <id>copy-resources3</id>
        <phase>process-resources</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${basedir}/somedirectory</outputDirectory>
            <overwrite>true</overwrite>
            <resources>
                <resource>
                    <directory>${basedir}/target/common-aws</directory>
                    <includes>
                        <include>*.xml</include>
                    </includes>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>
Naxi
  • 1,504
  • 5
  • 33
  • 72