Skip to content

Deploy maven projects

astrapi69 edited this page May 1, 2016 · 8 revisions

Here is small description how to deploy with maven and what you have to make before.

For a detail description follow this link:deploy-to-maven-central-repository

prerequisite

  • You have a registration on sonatype
  • The projects are well documented as needed for deployment

install gpg

  • In ubuntu gpg is already installed, if not install it afterwards.
  • Generate a key pair
  • Distribute your public key

For a detail description follow this link:how-to-generate-pgp-signatures-with-maven

  • Set up your settings.xml
<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
                        https://maven.apache.org/xsd/settings-1.0.0.xsd">
	<localRepository />
	<interactiveMode />
	<usePluginRegistry />
	<offline />
	<pluginGroups />
	<servers>
		<server>
			<id>ossrh</id>
			<username>YOUR-USERNAME</username>
			<password>YOUR-PW-FROM-SONATYPE-REGISTRATION</password>
		</server>
	</servers>
	<mirrors />
	<proxies />
	<profiles>
		<profile>
			<id>ossrh</id>
			<properties>
				<gpg.keyname>YOUR-KEYNAME</gpg.keyname>
				<gpg.passphrase>YOUR-PASSPHRASE</gpg.passphrase>
				<gpg.defaultKeyring>false</gpg.defaultKeyring>
				<gpg.useagent>true</gpg.useagent>
				<gpg.lockMode>never</gpg.lockMode>
				<gpg.homedir>/home/YOUR-USERNAME/.gnupg</gpg.homedir>
				<gpg.publicKeyring>/home/YOUR-USERNAME/.gnupg/pubring.gpg</gpg.publicKeyring>
				<gpg.secretKeyring>/home/YOUR-USERNAME/.gnupg/secring.gpg</gpg.secretKeyring>
			</properties>
		</profile>
	</profiles>
	<activeProfiles />
</settings>

You have to replace the placeholders of course with your credetials.

Create a maven profile in your pom.xml


	<profiles>

		<profile>
			<id>oss.sonatype.org-staged-release</id>
			<!-- This is the profile to use for releasing into the staged release
				repo. We need to sign the artifacts. -->
			<activation>
				<property>
					<name>performRelease</name>
					<value>true</value>
				</property>
			</activation>

			<build>
				<plugins>

					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-javadoc-plugin</artifactId>
					</plugin>

					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-source-plugin</artifactId>
					</plugin>

					<plugin>
						<inherited>true</inherited>
						<groupId>org.sonatype.plugins</groupId>
						<artifactId>nexus-staging-maven-plugin</artifactId>
					</plugin>

					<plugin>
						<inherited>true</inherited>
						<artifactId>maven-gpg-plugin</artifactId>
					</plugin>

				</plugins>
			</build>

			<distributionManagement>
				<snapshotRepository>
					<id>ossrh</id>
					<name>Sonatype Nexus Snapshots</name>
					<url>https://oss.sonatype.org/content/repositories/snapshots</url>
				</snapshotRepository>
				<repository>
					<id>ossrh</id>
					<name>Nexus Release Repository</name>
					<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
				</repository>
			</distributionManagement>

		</profile>

	</profiles>

Before deployment it is recommended to run the javadoc goal on project like this:

mvn javadoc:javadoc

Now you can run from your mvn-project the deploy command like this:

mvn clean install deploy:deploy -P oss.sonatype.org-staged-release

Note: you will be prompt for the passphrase. If you run it from eclipse no passphrase is prompt.

Clone this wiki locally