2

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.

Bhargav Teja
  • 431
  • 6
  • 19

2 Answers2

2
<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>
Bhargav Teja
  • 431
  • 6
  • 19
0

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107