5

I used maven-dependency-plugin to copy the current artifact into a custom directory :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.8</version>
    <executions>
        <execution>
            <id>copy-to-dsf-server</id>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                    </artifactItem>
                </artifactItems>
                <outputDirectory>${tomcat.dsf.dir}/lib/pacifisc</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

But when the artifact version changes I have two versions of the same jar into the destination directory. How can I delete the old version ?

Regards, Arnaud

Arnaud
  • 742
  • 7
  • 23

1 Answers1

10

I finally used the maven-clean-plugin :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <id>clean-dsf-server</id>
            <phase>package</phase>
            <goals>
                <goal>clean</goal>
            </goals>
            <configuration>
                <excludeDefaultDirectories>true</excludeDefaultDirectories>
                <filesets>
                    <filesets>
                        <directory>${tomcat.dsf.dir}/lib/pacifisc</directory>
                        <includes>
                            <include>${project.artifactId}*.jar</include>
                        </includes>
                    </filesets>
                </filesets>
            </configuration>
        </execution>
    </executions>
</plugin>
Arnaud
  • 742
  • 7
  • 23
  • 1
    Doesn't work anymore I guess. Got this error: " Could not find goal 'clean' in plugin org.apache.maven.plugins:maven-dependency-plugin:2.10 among available goals analyze, analyze-dep-mgt, analyze-duplicate, analyze-only, analyze-report, build-classpath, copy, copy-dependencies, display-ancestors, get, go-offline, help, list, list-repositories, properties, purge-local-repository, resolve, resolve-plugins, sources, tree, unpack, unpack-dependencies" – Dchucks Aug 15 '18 at 11:02
  • 'clean' is a goal of maven-clean-plugin. Do you add it like the answer ? – Arnaud Aug 16 '18 at 22:35