Usage

Brief examples on how to use the Copy Maven Plugin's goals.

Copy a single file during maven build

Use this example to copy a file during maven build.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>copy-file</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
              <destinationFile>target/someDir/environment.properties</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Copy multiple files during a maven build

The same as the previous example, but this time it will copy a directory instead of a file

<project>
  ...
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
                  <destinationFile>target/someDir/environment.properties</destinationFile>
                </fileSet>
                <fileSet>
                  <sourceFile>src/someDirectory/test.logback.xml</sourceFile>
                  <destinationFile>target/someDir/logback.xml</destinationFile>
                </fileSet>                
              </fileSets>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Rename a file during maven build

The same as the first example, but this time it will do a rename instead of copy

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>rename-file</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>rename</goal>
            </goals>
            <configuration>
              <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
              <destinationFile>target/someDir/environment.properties</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Rename a directory during maven build

Similar to the above example, but this time it will do a rename a directory

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>rename-file</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>rename</goal>
            </goals>
            <configuration>
              <sourceFile>target/someDirectory/</sourceFile>
              <destinationFile>target/someOtherDirectory/</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Rename multiple files during maven build

The same as the second example, but this time it will do a rename instead of copy

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>rename-file</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>rename</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
                  <destinationFile>target/someDir/environment.properties</destinationFile>
                </fileSet>
                <fileSet>
                  <sourceFile>src/someDirectory/test.logback.xml</sourceFile>
                  <destinationFile>target/someDir/logback.xml</destinationFile>
                </fileSet>                
              </fileSets>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Rename multiple files/directories during maven build

The same as the second example, but this time it will do a rename instead of copy

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.kohlschutter.mavenplugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
          <execution>
            <id>rename-file</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>rename</goal>
            </goals>
            <configuration>
              <fileSets>
                <fileSet>
                  <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
                  <destinationFile>target/someDir/environment.properties</destinationFile>
                </fileSet>
                <fileSet>
                  <sourceFile>src/someFolder/</sourceFile>
                  <destinationFile>target/someOtherFolder/</destinationFile>
                </fileSet>                
              </fileSets>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>