Skip to content

Instantly share code, notes, and snippets.

@pinguet62
Last active June 11, 2024 20:28
Show Gist options
  • Save pinguet62/f06dd96911ba3a955ed4cc5598489c10 to your computer and use it in GitHub Desktop.
Save pinguet62/f06dd96911ba3a955ed4cc5598489c10 to your computer and use it in GitHub Desktop.

Deploy to Nexus

JIRA

https://issues.sonatype.org

  • Username: OSSRH_USERNAME

  • Password: OSSRH_PASSWORD

  • Summary : description rapide du projet

  • GroupId : groupId du projet Maven. Ce groupe doit reprendre le nom de domaine du projet (e.g. : fr.xebia, com.googlecode.myproject, etc.)

  • Project URL : l’url du projet (e.g. http://xebia-france.googlecode.com/

  • SCM URL : l’url du gestionnaire de source (e.g. http://xebia-france.googlecode.com/svn/)

  • Nexus Username : le ou les logins de connexion au JIRA : https://issues.sonatype.org/

  • Already Sync To Central : indique si des versions de l’artefact ont déjà été déployées sur le Maven Central Repository (si oui, Sonatype les réintégrera dans le fichier maven-metadata.xml)

  • Description : toute information complémentaire

setting.xml

<settings>
	...
	<servers>
		<server>
			<id>ossrh</id>
			<username>${OSSRH_USERNAME}</username>
			<password>${OSSRH_PASSWORD}</password>
		</server>
	</servers>
	...
</settings>

POM

  • <id>ossrh</id> : link between setting.xml and pom.xml
<project>
    <modelVersion>...</modelVersion>

    <groupId>fr.pinguet62</groupId>
    <artifactId>%PROJECT%</artifactId>
    <version>...</version>
    <packaging>...</packaging>

    <name>${project.groupId}:${project.artifactId}</name>
    <description>...</description>
    <url>https://github.com/pinguet62/%PROJECT%</url>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://oss.sonatype.org</nexusUrl>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>PINGUET Julien</name>
            <email>[email protected]</email>
            <url>https://github.com/pinguet62</url>
            <roles>
                <role>architect</role>
                <role>developer</role>
            </roles>
            <timezone>+1</timezone>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/pinguet62/reactor-call-stack</url>
        <connection>scm:git:[email protected]:pinguet62/reactor-call-stack.git</connection>
        <developerConnection>scm:git:[email protected]:pinguet62/reactor-call-stack.git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
    </distributionManagement>
</project>

GPG

http://central.sonatype.org/pages/working-with-pgp-signatures.html https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key#generating-a-gpg-key

  1. Générer les clés :

    1. Commande : gpg --gen-key
    2. Type : (1) RSA et RSA (par défaut)
    3. Taille : 2048
    4. Expiration : /
    5. Nom + email + Commentaire
    6. Passphrase (pour sécuriser la clé privée) : %PASSPHRASE%

    Résultat : Empreinte de la clef = XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

  2. Lister les clés :

    1. Commande : gpg --list-keys
    2. Résultat :
    pub   %SIZE%R/%PUBLIC_KEY_ID% %CREATION_DATE%
    uid      [  ultime ] %NAME% (%COMMENT%) <%EMAIL%>
    sub   %SIZE%R/%PRIVATE_KEY_ID% %CREATION_DATE%
    
  3. Publier la clé :

    1. gpg --keyserver keyserver.ubuntu.com --send-keys %PUBLIC_KEY_ID%
  4. Test : mvn package gpg:sign -Dgpg.passphrase=%GPG_PASSPHRASE%

  5. Exporter clé privée : gpg --armor --export-secret-keys %PUBLIC_KEY_ID%

Publication

Options :

  • Sélection de la clé publique : -Dgpg.keyname= %PUBLIC_KEY%
  • Passphrase : -Dgpg.passphrase=%GPG_PASSPHRASE%
  1. SNAPSHOT :

    1. Commande : mvn deploy (appelle maven-gpg-plugin & nexus-staging-maven-plugin)
    2. https://oss.sonatype.org/content/repositories/snapshots
  2. RELEASE :
    http://blog.jetoile.fr/2010/04/le-plugin-release-un-peu-demystifie.html

    1. mvn release:clean
    2. Préparer : mvn release:prepare
    3. Publier : mvn release:perform
  3. Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2

  4. Promote staged artifacts into repository 'Releases'

  5. Download snapshot and release artifacts from group https://oss.sonatype.org/content/groups/public/fr/pinguet62/

  6. Download snapshot, release and staged artifacts from staging group https://oss.sonatype.org/content/groups/staging/fr/pinguet62/

URL Env. 📥 Upload / 📤 Download
https://oss.sonatype.org/content/groups/public/fr/pinguet62/ Snapshot+Release group 📤 down
https://oss.sonatype.org/content/groups/staging/fr/pinguet62/ Staging group 📤 down
https://oss.sonatype.org/content/repositories/snapshots/fr/pinguet62/ Snapshot 📥 up & 📤 down
https://oss.sonatype.org/content/repositories/staging/fr/pinguet62/ Staging 📤 down
https://oss.sonatype.org/service/local/staging/deploy/maven2/ (Staging +) Release 📥 up
https://oss.sonatype.org/content/repositories/releases/fr/pinguet62/ Release 📤 down

Console Nexus : https://oss.sonatype.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment