Skip to content

Commit 7d50ae7

Browse files
Copilothossain-khan
andcommitted
Add Maven publishing configuration for GitHub Packages
Co-authored-by: hossain-khan <[email protected]>
1 parent 5a62efa commit 7d50ae7

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,40 @@ JSON5 extends JSON with the following features:
2020
Add the dependency to your `build.gradle.kts`:
2121

2222
```kotlin
23+
repositories {
24+
maven {
25+
name = "GitHubPackages"
26+
url = uri("https://maven.pkg.github.com/hossain-khan/json5-kotlin")
27+
credentials {
28+
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
29+
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
30+
}
31+
}
32+
}
33+
2334
dependencies {
24-
implementation("io.github.json5:json5-kotlin:VERSION")
35+
implementation("hossain.dev:json5kt:1.0.0")
2536
}
2637
```
2738

39+
### Authentication for GitHub Packages
40+
41+
To access GitHub Packages, you need to authenticate with GitHub. You can do this by:
42+
43+
1. **Using environment variables:**
44+
```bash
45+
export USERNAME=your_github_username
46+
export TOKEN=your_github_personal_access_token
47+
```
48+
49+
2. **Using gradle.properties:**
50+
```properties
51+
gpr.user=your_github_username
52+
gpr.key=your_github_personal_access_token
53+
```
54+
55+
You can generate a personal access token at [GitHub > Settings > Developer settings > Personal access tokens](https://github.com/settings/tokens) with `read:packages` permission.
56+
2857
## Usage
2958

3059
### Basic Parsing and Stringifying

lib/build.gradle.kts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("buildsrc.convention.kotlin-jvm")
44
alias(libs.plugins.kover)
55
alias(libs.plugins.kotlinPluginSerialization)
6+
`maven-publish`
67
}
78

89
dependencies {
@@ -21,3 +22,62 @@ dependencies {
2122
tasks.test {
2223
useJUnitPlatform()
2324
}
25+
26+
// Configure JAR to include sources
27+
val sourcesJar by tasks.registering(Jar::class) {
28+
archiveClassifier.set("sources")
29+
from(sourceSets.main.get().allSource)
30+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
31+
}
32+
33+
// Publishing configuration
34+
publishing {
35+
publications {
36+
register<MavenPublication>("maven") {
37+
groupId = "hossain.dev"
38+
artifactId = "json5kt"
39+
version = "1.0.0"
40+
41+
from(components["java"])
42+
artifact(sourcesJar)
43+
44+
pom {
45+
name.set("JSON5 Kotlin")
46+
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.")
47+
url.set("https://github.com/hossain-khan/json5-kotlin")
48+
49+
licenses {
50+
license {
51+
name.set("MIT License")
52+
url.set("https://opensource.org/licenses/MIT")
53+
}
54+
}
55+
56+
developers {
57+
developer {
58+
id.set("hossain-khan")
59+
name.set("Hossain Khan")
60+
email.set("[email protected]")
61+
}
62+
}
63+
64+
scm {
65+
connection.set("scm:git:git://github.com/hossain-khan/json5-kotlin.git")
66+
developerConnection.set("scm:git:ssh://github.com:hossain-khan/json5-kotlin.git")
67+
url.set("https://github.com/hossain-khan/json5-kotlin")
68+
}
69+
}
70+
}
71+
}
72+
73+
repositories {
74+
maven {
75+
name = "GitHubPackages"
76+
url = uri("https://maven.pkg.github.com/hossain-khan/json5-kotlin")
77+
credentials {
78+
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
79+
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)