Publish JAR on Gradle on GitHub Package Registry

GitHub Package Registry

Now that I've finally signed up for the beta of Package Registry, an artifact publishing service on GitHub, I'll try to publish the JAR from the Maven repository. The repository used for the experiment is here. Official

Creating a token

Package permissions are separate from the repository, so even people with existing tokens will probably need to reissue / reconfigure.

キャプチャ.PNG

This time, set the user name and token in gradle.properties. You can use environment variables in this area as you like.

gradle.properties


GITHUB_USER = minebreaker
GITHUB_TOKEN = [[token]]

build.gradle

Use the regular Maven Publish plugin.

apply plugin: 'maven-publish'

publishing {
    repositories {
        maven {
            name = "github"
            url = 'https://maven.pkg.github.com/minebreaker/Abukuma'
            credentials {
                username = project.hasProperty("GITHUB_USER") ? GITHUB_USER : ''
                password = project.hasProperty("GITHUB_TOKEN") ? GITHUB_TOKEN : ''
            }
        }
    }

    publications {
        maven(MavenPublication) {
            version '0.0.0.1-EXPLORING_GITHUB_REGISTRY'

            pom {
                url 'https://github.com/minebreaker/Abukuma'
                licenses {
                    license {
                        name = 'MIT'
                    }
                }
            }

            from components.java
            artifact sourcesJar
            artifact javadocJar
        }
    }
}

Specify GitHub as the package publishing destination with repositories {}. pom is appropriate. Now replace the URL minebreaker and Abukuma with your username and repository.

Groups, artifacts and versions are used as-is from the project settings by default. In the above, version has been changed to make it clear that it is for experimentation (note that it cannot be deleted basically).

upload

Execute the publishMavenPublicationToGithubRepository task. It seems that the task will be set automatically from name = github in the above repository settings.

When I ran it, unfortunately the task failed halfway, only the JAR of the class file was exposed, and the Javadoc and source failed to upload. It's unclear if the settings are bad, if you're using Gradle badly, or if GitHub is bad. Seeking knowledge.

Use the library

Officially, the URL was https://maven.pkg.github.com/OWNER, but ** failed if the repository name was not included **. It's unclear if it's a specification, a bug, or a documentation error. Also, I can't find a setting to make the registry public, and I have to give credentials to the download (even though the source is public ...). Therefore, the settings are as follows.

repositories {
    maven {
        url = 'https://maven.pkg.github.com/minebreaker/Abukuma'
        credentials {
            username = project.hasProperty("GITHUB_USER") ? GITHUB_USER : ''
            password = project.hasProperty("GITHUB_TOKEN") ? GITHUB_TOKEN : ''
        }
    }
}

dependencies {
    implementation 'rip.deadcode.abukuma3:abukuma-jetty:0.0.0.2-EXPLORING_GITHUB_REGISTRY'
}

Summary

Impression that it is still in beta (although it is in beta). Next time I want to try Docker. -> Publish Docker Image to GitHub Package Registry

Recommended Posts

Publish JAR on Gradle on GitHub Package Registry
Publish Docker Image on GitHub Package Registry
Install gradle on mac
Try actions on GitHub [actions]
[Docker] Build a site on Hugo and publish it on GitHub