Last active
October 17, 2021 06:29
-
-
Save mikenoethiger/0c16dfe095a5fc60a4c249c42d0d0b70 to your computer and use it in GitHub Desktop.
Publish a Maven Package to GitHub with Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'maven-publish' | |
} | |
publishing { | |
repositories { | |
maven { | |
name = "GitHubPackages" | |
// Replace OWNER and REPOSITORY with your GitHub username/repository | |
// (must be both lowercase according to the documenations) | |
url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY") | |
credentials { | |
// Make sure to generate a token with write-packages and read-packages permission: https://github.com/settings/tokens/new | |
// You can either store the username and token in ~/.gradle/gradle.properties (use the gpr.user and gpr.key keys) | |
// Or you can store them as environment variables e.g. in ~/.bash_profile or ~/.zsh depending on your shell (GITHUB_USERNAME and GITHUB_TOKEN keys) | |
// Or you pass them via CLI: gradle publish -Pgpr.user=username -Pgpr.key=token | |
// See at EOF for examples on how to store the credentials | |
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME") | |
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") | |
} | |
} | |
} | |
publications { | |
gpr(MavenPublication) { | |
groupId = 'org.group' | |
artifactId = 'artifact' | |
version = '0.1' | |
from(components.java) | |
} | |
} | |
} | |
// Store this in ~/.gradle/gradle.properties | |
// gpr.user=github-username | |
// gpr.key=github-token | |
// Or store this in ~/.bash_profile or ~/.zsh or whatever shell you're using | |
// export GITHUB_USERNAME="username" | |
// export GITHUB_TOKEN="token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment