How do I integrate GitHub packages

I want to publish my project to the GitHub packages.

However, I use gradle and the explanation of it is a bit confusing for me.

The reason why I ask this in the “GitHub Actions” category is, that I want to automate this using GitHub Actions.

I already have a setup, that runs a gradle task, to publish the jars to Bintray, when I create a new release.

This is my current setup for GitHub Actions:

name: Bintray Upload-task

on:
  release:
    types: [published]
    branches:
    - master


jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Build with Gradle
      env:
        bintrayUser: ${{ secrets.bintrayUsername }}
        bintrayApiKey: ${{ secrets.bintrayApiKey }}
      run: ./gradlew bintrayUpload

And my current build.gradle looks like this:

plugins{
    id 'com.jfrog.bintray' version '1.8.4'
    id 'java-library'
    id 'idea'
    id 'maven-publish'
    id 'maven'
}

group = 'com.andre601'
version = '2.3.9'

sourceCompatibility = targetCompatibility = 1.8

jar{
    baseName = 'JavaBotBlockAPI'
}

repositories{
    mavenCentral()
    jcenter()
}

dependencies{
    api group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2'
    api group: 'org.json', name: 'json', version: '20190722'
    api group: 'org.jetbrains', name: 'annotations', version: '17.0.0'
    api(group: 'net.dv8tion', name: 'JDA', version: '4.0.0_52'){
        exclude(module: 'opus-java')
    }
    api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.0'
}

task sourcesJar(type: Jar, dependsOn: classes){
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc){
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts{
    archives sourcesJar
    archives javadocJar
}

bintray{
    user = System.getenv("bintrayUser")
    key = System.getenv("bintrayApiKey")
    publications = ['JavaBotBlockAPIRelease']
    pkg{
        repo = 'maven'
        name = 'JavaBotBlockAPI'
        licenses = ['MIT']
        vcsUrl = 'https://github.com/botblock/JavaBotBlockAPI'
        version{
            name = project.version
            released = new Date()
        }
    }
}

publishing{
    publications{
        JavaBotBlockAPIRelease(MavenPublication){
            from components.java
            groupId group
            artifactId archivesBaseName
            version version
            artifact javadocJar
            artifact sourcesJar
        }
    }
}

How would I now go about adding GitHub packages to it, for uploading the jars there?

Hello!

I was playing the last week with this in an example project, this is how the Action looks like:

https://github.com/dummy-org-gsd-days/spring-boot-example/blob/master/.github/workflows/master.yml#L44

And this is the gradle configuration (using the Kotlin DSL):

https://github.com/dummy-org-gsd-days/spring-boot-example/blob/master/build.gradle.kts

The uploaded package looks like this:

https://github.com/dummy-org-gsd-days/spring-boot-example/packages/34003

I hope it helps!

Okay. But it still doesn’t answer to me how I would implement it to work right next to uploading the files to Bintray

I’m generally confused and would really appreciate some help here.

I now integrated the gradle task like this into my project:

https://github.com/botblock/JavaBotBlockAPI/blob/ac84b3566ed6ec52b3efe470efb94da7c30d4f84/build.gradle#L75-L89

I setup the gradle.yml like this:

https://github.com/botblock/JavaBotBlockAPI/blob/ac84b3566ed6ec52b3efe470efb94da7c30d4f84/.github/workflows/gradle.yml#L23-L26

But the action did fail:

https://github.com/botblock/JavaBotBlockAPI/commit/ac84b3566ed6ec52b3efe470efb94da7c30d4f84/checks?check_suite_id=279484333#step:5:40

I want this to work, but I’m really lost right now.