Skip to content

Commit

Permalink
Adds missing information for publishing to Maven Central
Browse files Browse the repository at this point in the history
  • Loading branch information
jycr committed Jul 16, 2023
1 parent 5d0011d commit 8405c0d
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/publish_to_maven_central.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow will build a Java project with Maven and publish artifact to Maven Central (https://search.maven.org)
#
# After deploy to https://s01.oss.sonatype.org finished, manual steps is required :
# - Go to: https://s01.oss.sonatype.org/#stagingRepositories
# - Check upload and if all is right, "Close" corresponding Staging Repository
# - "Release" corresponding Staging Repository
# - Wait some hours and then check availability of release on Maven central: https://search.maven.org/search?q=g:io.ecocode
#
# Additional information:
# - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-the-maven-central-repository
# - https://blogs.itemis.com/en/github-actions-releasing-artifacts-into-maven-central

name: Publish package to the Maven Central Repository

on:
release:
types: [ published ]

jobs:
publish:
name: Deploy to Maven central
runs-on: ubuntu-latest

steps:
# Checks out a copy of project's repository.
- name: Checkout
uses: actions/checkout@v3

# Sets up the Java JDK, and also configures the Maven `settings.xml` file to add authentication for the
# `ossrh` repository using the `OSSRH_USERNAME` and `OSSRH_PASSWORD` environment variables.
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
server-id: 'ossrh' # must match the serverId configured for the nexus-staging-maven-plugin in `pom.xml`
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Substituted with the value stored in the referenced secret
gpg-passphrase: MAVEN_GPG_PASSPHRASE # Env var that holds the key's passphrase

- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

# Runs the Maven command to publish to the `ossrh` repository.
# The `OSSRH_USERNAME` environment variable will be set with the contents of your `OSSRH_USERNAME` secret,
# and the `OSSRH_PASSWORD` environment variable will be set with the contents of your `OSSRH_TOKEN` secret.
- name: Publish package
run: mvn --batch-mode deploy -Pmaven-central-publishing
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
115 changes: 115 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,61 @@
</license>
</licenses>

<developers>
<!--
Mandatory information to be able to publish to Maven Central:
https://central.sonatype.org/publish/requirements/#developer-information
-->
<developer>
<name>Gilles Grousset</name>
<email>zippy1978@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>Maxime Malgorn</name>
<email>utarwyn@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>Geoffrey Lalloué</name>
<email>glalloue@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>David DE CARVALHO</name>
<email>dedece35@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>Olivier Le Goaër</name>
<email>olegoaer@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>Julien Hertout</name>
<email>jhertout@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>Jules Delecour</name>
<email>jules-delecour-dav@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
<developer>
<name>DUBOIS Maxime</name>
<email>mdubois81@users.noreply.github.com</email>
<organization>green-code-initiative</organization>
<organizationUrl>https://github.com/green-code-initiative</organizationUrl>
</developer>
</developers>

<modules>
<module>ecocode-rules-specifications</module>
<module>python-plugin</module>
Expand Down Expand Up @@ -247,4 +302,64 @@
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>maven-central-publishing</id>
<!--
For publishing in Maven Central.
For more information:
- https://central.sonatype.org/publish/publish-guide/#deployment
- https://central.sonatype.org/publish/release/#login-into-ossrh
-->

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin><!--
For publishing in Maven Central,
see: https://central.sonatype.org/publish/publish-maven/#distribution-management-and-authentication
-->
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin><!--
For publishing in Maven Central, GPG key must be published to one of following servers:
- keyserver.ubuntu.com
- keys.openpgp.org
- pgp.mit.edu
For more informatino: https://central.sonatype.org/publish/requirements/gpg/#distributing-your-public-key
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit 8405c0d

Please sign in to comment.