Maven: how to export project with sources and dependencies

廉价感情. 提交于 2019-11-27 20:04:57

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.

Actually, there is nothing that will create a bundle with sources and dependencies out of the box. For this, you'll need to use a combination of the some plugins.

For dependencies, the Maven 2 Dependency Plugin and its copy-dependencies will help as pointed out by cetnar.

For sources, you might need the Maven Source Plugin and its source:aggregate goal (or maybe the Maven Assembly Plugin and the pre-defined src descriptor but source:aggregate is handy for multi-modules builds).

To bind the whole thing together (and maybe unpack sources), I'd use the Maven Assembly Plugin.

War with sources

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <webResources>
        <resource>
          <directory>${build.sourceDirectory}</directory>
          <targetPath>src</targetPath>
        </resource>
      </webResources>
    </configuration>
  </plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!