Reputation: 253
I would like to put a project on the nexus repository on sonatype (oss.sonatype.or) directly from eclipse using the deploy-plugin. I was close, but no cigar. I can build the -source.jar, and the -javadoc.jar files, and get everything signed with gpg-plugin, but when I deployed there were some errors. Can anyone share a typical pom.xml for this? Thanks.
Upvotes: 2
Views: 3636
Reputation: 253
Update: Per request: Detailed instructions for Setting up Eclipse to Deploy to Maven Central Repository (repo1.maven.org)
Start with an Eclipse Java Project. Convert it to a Maven project using m2e. The requirements for deploying a useful library to the Central Repository are
1: Good code. Just use common sense. Don’t put garbage up there. Test it.
2: Javadocs. Comment all your classes and methods. Create a /src/main/javadoc directory. Use a javadoc plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
3: Source Code: Use a source code plugin:
<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>
4: Get a gpg id and key and get it ‘registered’ by following the Sonatype instructions for setting it up with Maven: see https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven Add plugin …
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
And .m2/settings.xml
<profiles>
<profile>
<id>gpg</id>
<properties>
<gpg.passphrase>*******</gpg.passphrase>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>gpg</activeProfile>
</activeProfiles>
5: Add maven deploy plugin. This stops the regular deploy phase:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
6: Add sonatype plugin: Note: you will be able to get he stagingProfileId once you have been granted access to the repository.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.4.8</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<stagingProfileId>***********</stagingProfileId>
</configuration>
</plugin>
7: Read the Sonatype Maven Repository usage guide carefully: Do the extra things that your POM needs, such as a licenses section, scm section, developers section, and parent section. https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide It will tell you how to sign up and open a ticket. Once you have a ticket open, then you have access to the Sonatype Nexus site at https://oss.sonatype.org. That is where you can find your stagingProfileId that is needed above. Add the server information to your .m2/settings.xml
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>yourusername</username>
<password>yourpassword</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>yourusername</username>
<password>yourpassword</password>
</server>
</servers>
8: Finally, from eclipse, create a maven runtime configuration: Right click on the project, choose Run As->Run Configurations. Create a new Maven Build, set the base directory to your project directory, and the goals as “clean deploy” Apply and run, but first run Mavin->Install to create your javadocs and source files locally so you can check for errors or warning messages.
Upvotes: 1
Reputation: 31567
Documentation about staging
This is snippet from my working configuration (without stagging)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.sample</groupId>
<artifactId>sample-app</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<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>
<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>
</plugins>
</build>
<distributionManagement>
<repository>
<id>nexus</id>
<url>https://repository.company.com/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<url>https://repository.company.com/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>secret_password</password>
</server>
</servers>
</settings>
mvn deploy
For attaching source:jar and javadoc:jar use configuration from Cookbook: How to attach source and javadoc artifacts?
Upvotes: 0