-
Notifications
You must be signed in to change notification settings - Fork 4
Publishing Releases
The publishGithub task builds your project and uploads one or more JARs as assets on a GitHub release.
- Runs
build(the task depends on it) - Resolves
owner,repo,version,tag, andreleaseName(from the extension or auto-detected) - Checks whether a release for the resolved tag already exists - if so, assets are uploaded to that existing release; if not, a new release is created
- Uploads the configured JAR(s)
Publishing is configured via the publishGithub { } extension, which can also be accessed nested inside github { publish { } }. Both paths configure the same object.
| Field | Type | Default | Description |
|---|---|---|---|
owner |
String |
auto-detected from git remote origin | GitHub user or organisation |
repo |
String |
auto-detected from git remote origin | Repository name |
version |
String |
project.version |
Version string used for dependency resolution by consumers |
tag |
String |
same as version
|
Git tag pushed to GitHub (e.g. "v1.0.0") |
releaseName |
String |
same as tag
|
Human-readable release title shown on GitHub (e.g. "Release 1.0.0") |
jar |
File |
auto-selected from build/libs/
|
Single JAR to upload (ignored when artifacts is non-empty) |
publishGithub {
owner = "my-org"
repo = "my-repo"
version = "1.0.0"
tag = "v1.0.0"
releaseName = "Release 1.0.0"
jar = file("build/libs/my-lib.jar")
}All fields are optional. With no configuration at all the plugin auto-detects everything:
// version must be set on the project
version = "1.0.0"
// owner/repo come from git remote origin
// tag = version, releaseName = tag
// jar = shadow/fat JAR or first .jar in build/libs/github {
accessToken = "ghp_YOUR_TOKEN_HERE"
publish {
owner = "my-org"
repo = "my-repo"
version = "1.0.0"
tag = "v1.0.0"
releaseName = "Release 1.0.0"
jar = file("build/libs/my-lib.jar")
}
}Use the artifacts { } block to upload multiple JARs in a single release. Each artifact is identified by a classifier string that consumers use to select it.
publishGithub {
version = "1.0.0"
tag = "v1.0.0"
releaseName = "Release 1.0.0"
artifacts {
artifact {
classifier = "" // default artifact - uploaded as my-repo.jar
jar = file("build/libs/my-lib.jar")
}
artifact {
classifier = "api" // uploaded as my-repo-api.jar
jar = file("build/libs/my-lib-api.jar")
}
artifact {
classifier = "fat" // uploaded as my-repo-fat.jar
jar = file("build/libs/my-lib-fat.jar")
}
}
}| Classifier | Asset file name |
|---|---|
"" (empty / default) |
repo.jar |
"api" |
repo-api.jar |
"fat" |
repo-fat.jar |
dependencies {
githubImplementation "my-org:my-repo:1.0.0" // downloads my-repo.jar
githubImplementation "my-org:my-repo:1.0.0:api" // downloads my-repo-api.jar
githubImplementation "my-org:my-repo:1.0.0:fat" // downloads my-repo-fat.jar
}When jar is not set and artifacts is empty, the plugin scans build/libs/ and picks:
- A JAR whose name contains
-standalone,-all, or-shadow(fat/shadow JAR) - Otherwise the first
.jarthat is not a-sources.jaror-javadoc.jar
If the release for the resolved tag already exists the task uploads assets to it rather than failing. This means re-running after a partial failure (e.g. a network drop mid-upload) is safe.
gradle publishGithub
The task automatically runs build first, so you do not need to run gradle build publishGithub separately.
Getting started
Using the plugin
Reference