gradlegithub-actionsgithub-packages

Uploaded package in github package are using number but jar is using all


I have an API that is built with gradle. This issue appeared when I moved to Java 21 (from 17) and gradle 8.6 (from 8.3): gradle is searching for myapi-dateOfDay-1.jar.

In the Github packages files are well registered. There is a jar known as myapi-dateOfDay-all.jar. There is pom file in maven-metadata.xml that refers to myapi-dateOfDay-1.pom.

As all of my projects that depend on this API find the pom.xml file and do not complain about dependency resolution failure. (But they don't get any jar file.)

How can I get gradle to find the jar file from the Github package?

Here is part of gradle file :

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    id 'java-library'
    id "maven-publish"
    id 'io.github.goooler.shadow' version '8.1.7'
}

java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))

publishing {
    repositories {
        maven {
            name = "github"
            url = uri("https://maven.pkg.github.com/MyOrg/MyAPI")
            credentials(HttpHeaderCredentials);
            authentication {
                header(HttpHeaderAuthentication)
            }
        }
    }
    publications {
        gpr(MavenPublication) {
            publication -> project.shadow.component(publication)
            groupId 'com.elikill58'
            artifactId 'myapi'
        }
    }
}

Here is the github actions that publish it:

name: Build with gradle

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: '21'
        cache: gradle
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build
      run: ./gradlew publish -PgithubAuthHeaderName='Authorization' -PgithubAuthHeaderValue='Bearer ${{ secrets.TOKEN }}'

Solution

  • I had to specify some specific jar name and be sure it's this one. Even the classifier wasn't took in count.

    Here is my final gradle file:

    import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
    
    plugins {
        id 'java-library'
        id "maven-publish"
        id 'io.github.goooler.shadow' version '8.1.7'
        id "eclipse"
    }
    
    java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
    
    publishing {
        repositories {
            maven {
                name = "github"
                url = uri("https://maven.pkg.github.com/MyOrg/MyAPI")
                credentials(HttpHeaderCredentials);
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
        }
        publications {
            gpr(MavenPublication) {
                artifact("build/libs/MyAPI-version.jar") {
                   builtBy shadowJar
                }
                groupId 'com.elikill58'
                artifactId 'myapi'
            }
        }
    }
    
    archivesBaseName = 'MyAPI'
    
    sourceSets.main {
        java.srcDirs = ['src']
        resources.srcDirs = ['resources']
    }
    
    compileJava.options.encoding = 'UTF-8'
    
    shadowJar {
        archiveBaseName.set('MyAPI')
        archiveClassifier.set(null)
    }
    
    build.dependsOn shadowJar