Attach sources & javadocs in maven project

Maven allows to publish project source code and javadoc with complied artifact. Maven source plugin and javadoc can do it easily for you.

Here is pom configuration for it.

Attaching source

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-sources</id>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Maven source plugin also allows to package test source codes

Attaching test source code

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-test-sources</id>
      <goals>
        <goal>test-jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Attaching javadocs

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-javadocs</id>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

you achieve it by issuing any of following maven commands

mvn package
mvn install

Please refer to maven plugin website for more information

source-plugin  http://maven.apache.org/plugins/maven-source-plugin/

javadoc-plugin http://maven.apache.org/plugins/maven-javadoc-plugin/

Java bug

I am Java professional, working on Enterprise Java from last 8 years.

More Posts - Website

Follow Me:
TwitterLinkedIn