skip to Main Content

In my Gradle project I have a hardcoded project version – SNAPSHOT.

When I push a new version – everything is OK, but if I push the same version for 2nd time – publishing fails. How can I tell GitHub that I want to override existing package?

For GitHub Actions I have a workflow to publish that project on every push to the main branch:

name: Publish package to GitHub Packages
on:
  push:
    branches: ['main']
jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'corretto'
          java-version: '18'
          cache: 'gradle'

      - name: Publish package
        uses: gradle/gradle-build-action@v2
        with:
          arguments: publish
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I’m expecting a new package with the same version to be publish to the GitHub Packages.

2

Answers


  1. Chosen as BEST ANSWER

    Since I did not found any GitHub Action for my task, I decided to create one: https://github.com/marketplace/actions/version-cleaner-action


  2. This is possible but first you need to delete that package version and then republish it.

    But keep in mind that:

    On GitHub if you have the required access, you can delete:

    • an entire private package
    • an entire public package, if there’s not more than 5000 downloads of any version of the package
    • a specific version of a private package
    • a specific version of a public package, if the package version doesn’t have more than 5,000 downloads
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search