Question

I include the following snippet in a projects 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 attaches the jar goal to the package phase. However doing "mvn clean ; mvn package" does not generate a project-sources.jar in the target directory.

EDIT: Propably i do not understand the comment from the website, which i quoted: "[The source:jar goal] Binds by default to the lifecycle phase: package." I expected that, when i include the plugin section as shown above maven already binds the source:jar goal to the package phase. Am i mistaking here? What does the comment mean?

matthias.

Was it helpful?

Solution

The documentation is a little misleading. The plugin has a default execution phase of package but there is no default goal. I believe that you have specify a goal in order for the plugin to work.

OTHER TIPS

You need to bind the plugin to a maven life-cycle goal for it to generate the source jar. Otherwise, you need to invoke it explicitly mvn source:jar.

As documented here, you can bind it to the jar goal.

Try this:

<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>

It uses then the default binding of jar-no-fork goal to package phase of the lifecycle and that's probably what you need here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top