Maven: Deploying Java Sources to Nexus

By default, mvn deploy will only package and deploy class JAR to Nexus. To deploy the source code too, we need to add the following plugin into pom.xml:-

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

Now, mvn deploy will deploy both class JAR and source code JAR to Nexus:-

In IntelliJ, when jumping into a class from the JAR, we are given the option to “Download Sources” or “Attach Sources…”.

For some reason, in order for “Download Sources” to work, we need to uncheck “Use Maven3 to import project”.

Now, when we click on “Download Sources”, it will download the sources directly from Nexus and display the source code.

Advertisements

One thought on “Maven: Deploying Java Sources to Nexus

  1. Derek E. Weeks

    Hello, I am Derek Weeks from Sonatype. We are really happy to see your blog discussing Nexus and we would love to bring it some more visibility. We recently started up a new Nexus community site with loads of articles, free training, videos, and members only features. If you are interested, we would love to cross-post your blog on the community, giving your article and you as the author more visibility to the rest of the Nexus community. I am sure others would find the article just as useful as I did. Our Nexus community site “TheNexus” can be found at: http://www.sonatype.org/nexus/

    Reach out to me at “weeks[at]sonatype dotcom” and I can introduce you to our Nexus community advocate, Mark Miller. We can then work to get your article up on the site. Of course, Sonatype will help with more visibility by promoting the article through our community, twitter, LinkedIn, G+, Facebook and other communities.

    Are you in? Let me know.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s