Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete old artifact version before copy dependencies

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

like image 989
Arnaud Avatar asked Feb 05 '14 00:02

Arnaud


People also ask

What is ArtifactItem in Maven?

public class ArtifactItem extends Object implements org.apache.maven.shared.transfer.dependencies.DependableCoordinate. ArtifactItem represents information specified in the plugin configuration section for each artifact.

Which Maven phase copy a project's artifact to the local repository for use as a dependency?

The dependency:copy goal can also be used to copy the just built artifact to a custom location if desired. It must be bound to any phase after the package phase so that the artifact exists in the repository.

What does mvn dependency resolve do?

Description: Goal that resolves the project dependencies from the repository.

What is Maven clean plugin?

The Clean Plugin is used when you want to remove files generated at build-time in a project's directory.


1 Answers

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>
like image 100
Arnaud Avatar answered Nov 24 '22 13:11

Arnaud