How to publish gradle plugins to gitlab package registry

Hi,

I was wondering if there are any tutorial/blogs/documentation sources how to publish gradle plugins to a gitlab package registry and version the related plugin artefacts with nebula.

All my attempts so far failed. The latest attempt failed because there seems to be no maven-metadata.xml present in the gitlab package registry:

   * What went wrong:
Execution failed for task ':publishNebulaPublicationToMavenRepository'.
> Failed to publish publication 'nebula' to repository 'maven'
   > Could not GET 'https://git.acme.net/api/v4/projects/1384/packages/maven/org/foobar/foobar-gradle-plugin/maven-metadata.xml'. Received status code 500 from server: Internal Server Error

My build.gradle in the plugin project looks like the following:

plugins {
    id 'java-gradle-plugin'
    id 'org.jetbrains.kotlin.jvm' version '1.7.10'
    id 'nebula.release' version '17.0.1'
    id 'maven-publish'
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
}

gradlePlugin {
    plugins {
        project {
            id = 'com.acme.project'
            implementationClass = 'com.acme.ProjectPlugin'
        }
    }
}

test {
    useJUnitPlatform()
}

task sourceJar(type: Jar) {
    from sourceSets.main.allSource
    classifier "sources"
}

publishing {
    publications {
        nebula(MavenPublication) {
            groupId 'org.foobar'
        }
    }

    repositories {
        maven {
            url "https://git.acme.net/api/v4/projects/1384/packages/maven"
            credentials(HttpHeaderCredentials) {
                name = "Private-Token"
                value = "glpat-fewfewfewfewfewfew"
            }
            authentication {
                header(HttpHeaderAuthentication)
            }
        }
    }
}

nebulaRelease {
    addReleaseBranchPattern("develop")
}

and my .gitlab-ci.yml like this:

.gradle_job:
  image: registry.acme.net/container/build/java:11.0.17
  cache:
    paths:
    - .gradle/wrapper/
    - .gradle/caches/
    - build/jib-cache
    key:
      files:
      - build.gradle
      - gradle/wrapper/gradle-wrapper.properties
      prefix: $CI_PROJECT_PATH_SLUG
  tags:
    - op-k-build
    - medium
    - amd64
  before_script:
    # set gradle user home into project dir for caching
    - export GRADLE_USER_HOME=`pwd`/.gradle

build:
  extends: .gradle_job
  stage: build
  coverage: '/Coverage: (\d+\.?\d+)%/'
  script:
    - ./gradlew clean check
  except:
    - tags
  artifacts:
    reports:
      junit: build/test-results/test/TEST-*.xml
    paths:
      - build/
    expire_in: 2 days

release.minor:
  extends: .gradle_job
  stage: deploy
  only:
    refs:
      - develop
    variables:
      - $CI_COMMIT_MESSAGE !~ /.*\b(Major|Patch|Chore):.*/ims
  script:
    # new minor version on each develop commit - except chore, major, patch
    - ./gradlew final -Prelease.scope=minor

release.major:
  extends: .gradle_job
  stage: deploy
  only:
    refs:
      - develop
    variables:
      - $CI_COMMIT_MESSAGE =~ /.*\bMajor:.*/ims
  script:
    # new major version when commit message starts with "major: "
    - ./gradlew final -Prelease.scope=major

release.patch:
  extends: .gradle_job
  stage: deploy
  only:
    refs:
      - develop
    variables:
      - $CI_COMMIT_MESSAGE =~ /.*\bPatch:.*/ims
  script:
    # new patch version when commit message starts with "patch: "
    - ./gradlew final -Prelease.scope=patch

release.candidate.minor:
  extends: .gradle_job
  stage: deploy
  only:
    - branches
  when: manual
  script:
    # new minor version release candidate on demand
    - ./gradlew final -Prelease.scope=minor publish

Would be really glad, if someone could point me to the right direction.

I don’t think that your URL for publishing is correct.
It is a GitHub API URL, not a Gradle package repository URL.
The docs at Publishing Java packages with Gradle - GitHub Docs show as URL https://maven.pkg.github.com/octocat/hello-world so it should probably be similar for you and not an API URL.

Besides that a 5xx error is never good.
You should report that to GitHub, because 5xx error always means something is messed up on the server side.
It should probably more be a 4xx server for requesting an invalid URL.

Ah, sorry, misread GitLab for GitHub.
Then the URL seems to be good, but still a 5xx error is not good.
I’d still tend to blame GitLab.
Maybe you find anything relevant in the GitLab logs?
And you should still report the 5xx error, but to GitLab, not GitHub. :slight_smile:

Hi,

Thx for your quick response! I figured out that it is related to this gitlab issue: Unable to get Maven package if GCS object storage is used and if proxy_download is disabled (#389241) · Issues · GitLab.org / GitLab · GitLab.

By re-configuring proxy_download in gitlab it suddenly started to work again.

1 Like