Bhargav Teja
Bhargav Teja

Reputation: 451

Copy a folder from one module to other module in Maven

Project structure

-MyProject
    |_ project1
            |_ dist
            |_ app
            |_ config
            |_ pom.xml
    |_ project2
            |_ pom.xml

I tried another way as below, but didn't work.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>install-jar</id>
            <phase>install</phase>
            <goals>
                <goal>copy</goal>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>MyProject</groupId>
                        <artifactId>project1</artifactId>
                        <version>1.0.0</version>
                    </artifactItem>
                </artifactItems>
                <outputDirectory>${project.build.directory}/assets/</outputDirectory>
                <stripVersion>true</stripVersion>
            </configuration>
        </execution>
    </executions>
</plugin>

I want to copy dist from project1 to project2 using maven. Could anyone tell me how to do this. Thanks.

Upvotes: 2

Views: 3579

Answers (2)

Bhargav Teja
Bhargav Teja

Reputation: 451

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dist</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/assets</outputDirectory>
                <overwrite>true</overwrite>
                <resources>
                    <resource>
                        <directory>../project1/dist/</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Upvotes: 2

Gerold Broser
Gerold Broser

Reputation: 14762

I always use the Wagon Maven Plugin for such:

Use this plugin to view and transfer resources between repositories using Maven Wagon.

See also this answer to Best practices for copying files with Maven.

Upvotes: 0

Related Questions