2

So I understand how I can package dependencies into my executable JAR, using jar-with-dependencies descriptor for maven-assembly-plugin.

However, I want to also create a source bundle(s), that not only includes sources of my project, but sources of all dependencies that are embedded in my executable JAR.

How can one achieve that?

Waqas Ilyas
  • 2,891
  • 14
  • 27

1 Answers1

3

This is what I used finally:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>src-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <classifier>sources</classifier>
                <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
                <outputDirectory>${project.build.directory}/sources</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

It copies the sources of all known dependencies recursively into the target/source directory. Pretty handy!

Note: Use unpack-dependencies goal to instead unpack all sources in destination directory.

Reference: https://maven.apache.org/plugins/maven-dependency-plugin/index.html

Waqas Ilyas
  • 2,891
  • 14
  • 27