|
| 1 | +# This workflow will build a Java project with Maven and publish artifact to Maven Central (https://search.maven.org) |
| 2 | +# |
| 3 | +# Additional information: |
| 4 | +# - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-the-maven-central-repository |
| 5 | +# - https://blogs.itemis.com/en/github-actions-releasing-artifacts-into-maven-central |
| 6 | +# - https://itnext.io/publishing-artifacts-to-maven-central-using-github-actions-a-step-by-step-guide-fd65ef075fd4 |
| 7 | +# - https://github.com/naturalett/maven-hello-world/blob/main/.github/workflows/maven.yml |
| 8 | +name: Publish package to the Maven Central Repository |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + push: |
| 13 | + tags: [ "*" ] |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build, release and publish to Maven Central |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + # Checks out a copy of project's repository. |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + # Shallow clones should be disabled for a better relevancy of analysis |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + # Sets up the Java JDK, and also configures the Maven `settings.xml` file to add authentication for the |
| 29 | + # `ossrh` repository using the `OSSRH_USERNAME` and `OSSRH_TOKEN` environment variables. |
| 30 | + - name: Set up Project |
| 31 | + uses: actions/setup-java@v4 |
| 32 | + with: |
| 33 | + java-version-file: '.java-version' |
| 34 | + distribution: 'temurin' |
| 35 | + cache: 'maven' |
| 36 | + cache-dependency-path: 'pom.yml' |
| 37 | + # must match the serverId configured for the nexus-staging-maven-plugin in the POM |
| 38 | + server-id: ossrh |
| 39 | + server-username: OSSRH_USERNAME |
| 40 | + server-password: OSSRH_TOKEN |
| 41 | + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 42 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 43 | + |
| 44 | + - name: Cache SonarCloud packages |
| 45 | + uses: actions/cache@v3 |
| 46 | + with: |
| 47 | + path: ~/.sonar/cache |
| 48 | + key: ${{ runner.os }}-sonar |
| 49 | + restore-keys: ${{ runner.os }}-sonar |
| 50 | + |
| 51 | + # Runs the Maven command to publish to the `ossrh` repository. |
| 52 | + # The `OSSRH_USERNAME` environment variable will be set with the contents of your `OSSRH_USERNAME` secret, |
| 53 | + # and the `OSSRH_TOKEN` environment variable will be set with the contents of your `OSSRH_TOKEN` secret. |
| 54 | + - name: Build, analyze and publish package |
| 55 | + env: |
| 56 | + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 57 | + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} |
| 58 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 60 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 61 | + run: ./mvnw --batch-mode deploy org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar -Pmaven-central-publishing |
0 commit comments