-
Notifications
You must be signed in to change notification settings - Fork 0
Add Maven publishing support for GitHub Packages #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ plugins { | |
| id("buildsrc.convention.kotlin-jvm") | ||
| alias(libs.plugins.kover) | ||
| alias(libs.plugins.kotlinPluginSerialization) | ||
| `maven-publish` | ||
| } | ||
|
|
||
| dependencies { | ||
|
|
@@ -21,3 +22,62 @@ dependencies { | |
| tasks.test { | ||
| useJUnitPlatform() | ||
| } | ||
|
|
||
| // Configure JAR to include sources | ||
| val sourcesJar by tasks.registering(Jar::class) { | ||
| archiveClassifier.set("sources") | ||
| from(sourceSets.main.get().allSource) | ||
| duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
| } | ||
|
|
||
| // Publishing configuration | ||
| publishing { | ||
| publications { | ||
| register<MavenPublication>("maven") { | ||
| groupId = "hossain.dev" | ||
| artifactId = "json5kt" | ||
| version = "1.0.0" | ||
|
|
||
| from(components["java"]) | ||
| artifact(sourcesJar) | ||
|
|
||
| pom { | ||
| name.set("JSON5 Kotlin") | ||
| description.set("A robust JSON5 parser and serializer for Kotlin/JVM that extends JSON with helpful features like comments, trailing commas, and unquoted keys while maintaining full backward compatibility with JSON.") | ||
| url.set("https://github.com/hossain-khan/json5-kotlin") | ||
|
|
||
| licenses { | ||
| license { | ||
| name.set("MIT License") | ||
| url.set("https://opensource.org/licenses/MIT") | ||
| } | ||
| } | ||
|
|
||
| developers { | ||
| developer { | ||
| id.set("hossain-khan") | ||
| name.set("Hossain Khan") | ||
| email.set("[email protected]") | ||
| } | ||
| } | ||
|
|
||
| scm { | ||
| connection.set("scm:git:git://github.com/hossain-khan/json5-kotlin.git") | ||
| developerConnection.set("scm:git:ssh://github.com:hossain-khan/json5-kotlin.git") | ||
| url.set("https://github.com/hossain-khan/json5-kotlin") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| maven { | ||
| name = "GitHubPackages" | ||
| url = uri("https://maven.pkg.github.com/hossain-khan/json5-kotlin") | ||
| credentials { | ||
| username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") | ||
| password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I trigger maven publish to github package using this definition. When would I do it - what is the best practices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger publishing to GitHub Packages using this Gradle definition, you would use the following command from your terminal in the project root:
This command will execute the publishing block defined in your
build.gradle.ktsfile and upload your artifact (including your main JAR and sources JAR) to the GitHub Packages Maven repository specified in the configuration.How Authentication Works
gpr.userandgpr.key) or environment variables (USERNAMEandTOKEN).TOKENenvironment variable to a GitHub personal access token (withwrite:packagesandread:packagesscope).When and How to Publish (Best Practices)
Release Process:
main,master, or tag creation.Version Management:
versionfield in your publishing configuration to reflect semantic versioning and avoid overwriting packages.CI/CD Automation:
./gradlew publishafter running tests and checks.Example GitHub Actions step:
Local Publishing (for testing):
./gradlew publishlocally with your environment variables set to test the process.Recap
./gradlew publishLet me know if you want an example workflow file or more details!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Please provide example workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly! Here is an example GitHub Actions workflow to publish your Maven package to GitHub Packages using the Gradle configuration you provided.
Save this as .github/workflows/publish.yml in your repository:
How this works:
Best Practices:
Let me know if you want it to also publish on branch pushes, or if you need help customizing further!