Skip to content

Publishing

Lilly Tempest edited this page Jun 22, 2022 · 11 revisions

On this page we cover publishing to our repository.

PublishData

In order to make publishing easier we use our own plugin called publish data.

Importing

Add the eldonexus as plugin repository in your settings.gradle.kts

pluginManagement{
    repositories{
        gradlePluginPortal()
        // Use eldo nexus for gradle plugins
        maven("https://eldonexus.de/repository/maven-public/")
    }
}

Import the plugin in build.gradle.kts. Check the current version here

plugins {
    id("de.chojo.publishdata") version "version"
    `maven-publish`
}

Configuring

Configure publishData in your build.gradle.kts

// configure publish data
publishData {
    // We use the eldo nexus default repositories with "main" as our stable branch
    useEldoNexusRepos(useMain = true)
    // This would use "master" as our stable branch
    // useEldoNexusRepos()

    // We publish everything of the java component, which includes our compiled jar, sources and javadocs
    publishComponent("java")
}

Versioning

Please use semantic versioning when publishing.

Please do not append things like -SNAPSHOT or -DEV to your version. These will be added automatically by publishData if required.

Versioning on minecraft plugins

If you publish dev builds, you maybe want to include the commit hash in your version. This version can be provided by publishData.getVersion(true).

Building locally

The publish data detects if it is running in a github workflow. If it gets executed locally all builds will be marked as local builds.

In order to build with a correct version, which is not flagged as local set the env variable PUBLIC_BUILD to true.

 PUBLIC_BUILD=true ./gradlew build

Publishing

Now we need to configure the publishing settings.

This is easy now. We just need to configure the maven-publish in our build.gradle.kts

publishing {
    publications.create<MavenPublication>("maven") {
        // Configure our maven publication
        publishData.configurePublication(this)
    }

    repositories {
        // We add EldoNexus as our repository. The used url is defined by the publish data.
        maven {
            authentication {
                credentials(PasswordCredentials::class) {
                    // Those credentials need to be set under "Settings -> Secrets -> Actions" in your repository
                    username = System.getenv("NEXUS_USERNAME")
                    password = System.getenv("NEXUS_PASSWORD")
                }
            }

            name = "EldoNexus"
            setUrl(publishData.getRepository())
        }
    }
}

Configure Repository

Adding secrets

Add the credentials in your repository under "Settings -> Secrets -> Actions". The names need to be NEXUS_USERNAME and NEXUS_PASSWORD with their values.

Adding a publish workflow

Add this file under .github/workflows/ in our repository.

The file name doesnt matter.

Configure organization

If your repository is part of an organization you can add the secrets as organization secrets. This way they will be available in all repositories.

The path is the same "Settings -> Secrets -> Actions".

Build Types

PublishData depends on the git repository. It will not work outside a git repository. PublishData will detect the current branch and the current commit.

Stable builds

A stable build will be published to maven-releases when pushing on the master or main branch.
Stable releases can not be overridden once published.
The version returned by getVersion(true) and getVersion() will be always only the current version like 1.0.0.

Development builds

A development build will be published to maven-dev when pushing on a branch named dev or any branch starting with dev.
Development releases can be overridden once published. The older version will be no longer available.
The version returned by getVersion(true) will be always current version suffixed with DEV and the commit hash like 1.0.0-DEV-48378d7.
The version returned by getVersion() will be always current version suffixed with DEV like 1.0.0-DEV.

Snapshot builds

A snapshot build will be published to maven-snapshots when pushing on any other branch like feature branches.
Snapshot releases will be published to a snapshot repository containing all older snapshots.
The version returned by getVersion(true) will be always the current version suffixed with SNAPSHOT and the commit hash like 1.0.0-SNAPSHOT-48378d7.
The version returned by getVersion() will be always current version suffixed with SNAPSHOT like 1.0.0-SNAPSHOT.

Clone this wiki locally