How to create an archive of archives of project sources with maven

I include the following snippet in the project object model

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> </plugin> 

according to maven.apache.org the plugin joins the can target to the package phase. However, running "mvn clean; mvn package" does not create the project-sources.jar file in the destination directory.

EDIT: Appropriate, I do not understand the comment from the website I quoted: "[Source: target jar] Becomes the default lifecycle phase: package." I expected that when I turn on the plugin section as shown above, maven already binds the original target: jar to the package phase. Am I mistaken here? What does a comment mean?

Matthias.

+4
source share
3 answers

The documentation is a bit misleading. The plugin has a default execution phase for the package, but there is no default target. I believe that you specified a goal for the plugin to work.

+5
source

You need to bind the plugin to the maven lifecycle goal so that it can generate the source jar. Otherwise, you need to explicitly call it mvn source:jar .

As described here , you can bind it to a jar target.

+1
source

Try the following:

 <project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ... </project> 

In this case, the default jar-no-fork default binding to the package life cycle phase is used and probably what you need here.

0
source

All Articles