Maven: how to export project with sources and dependencies

glaz666 picture glaz666 · Nov 17, 2009 · Viewed 49.1k times · Source

I have Maven project with dependencies in repo and stuff. I want to "export" its sources with all dependencies so that I can successfully open it in IDE without Maven running on a machine.

When packaging project into war file, it has all dependencies packed with it.

So I want to have all that dependencies plus my sources gathered in one place, which can be opened with IDE (Eclipse or IDEA) all those libraries detected?

Answer

cetnar picture cetnar · Nov 17, 2009

Try maven-dependency-plugin with goal copy-dependencies

<project>
[...]
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>
[...]
</project>

PS.
Are you aware of maven and IDE integration (for Eclipse p.e.)? Maven can generate project for particular IDE and include all dependent jars as variables (pointing to these jars in local repository), so there is no need to use copy dependecies to subfolder.