Skip to content

Commit 78516e4

Browse files
author
Adrian Tosca
committed
publish configuration
1 parent 92039b3 commit 78516e4

12 files changed

+202
-14
lines changed

.github/workflows/publish-on-release.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ jobs:
1414
java-version: 17
1515
- uses: gradle/actions/setup-gradle@v3
1616
- run: ./gradlew build
17-
- run: ./gradlew publishAllPublicationsToOSSRHRepository
17+
- run: ./gradlew publish
18+
- run: ./gradlew jreleaserFullRelease
1819
env:
19-
ORG_GRADLE_PROJECT_OSSRHUsername: ${{ secrets.OSSRH_USERNAME }}
20-
ORG_GRADLE_PROJECT_OSSRHPassword: ${{ secrets.OSSRH_TOKEN }}
21-
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_KEY }}
22-
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
20+
ENV: "CI"
21+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
22+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
23+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
24+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
25+
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.JRELEASER_MAVENCENTRAL_TOKEN }}
26+
JRELEASER_GITHUB_TOKEN: ${{ secrets.JRELEASER_GITHUB_TOKEN }}

README.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# typeid-kotlin
22
![Build Status](https://github.com/aleris/typeid-kotlin/actions/workflows/build-on-push.yml/badge.svg)
3+
![Current Version](https://img.shields.io/badge/Version-0.0.4-blue)
34

45

56
## A Kotlin implementation of [TypeID](https://github.com/jetpack-io/typeid).
@@ -9,7 +10,7 @@ UUIDv7 standard. They provide a ton of nice properties that make them a great ch
910
as the primary identifiers for your data in a database, APIs, and distributed systems.
1011
Read more about TypeIDs in their [spec](https://github.com/jetpack-io/typeid).
1112

12-
Based on the Java implementation from [typeid-java](https://github.com/fxlae/typeid-java).
13+
Based on the Java implementation from [fxlae/typeid-java](https://github.com/fxlae/typeid-java).
1314

1415
This implementation adds a more complete type safety including id and their prefixes and uses an idiomatic Kotlin API.
1516

@@ -22,14 +23,14 @@ To use with Maven:
2223
<dependency>
2324
<groupId>earth.adi</groupId>
2425
<artifactId>typeid-kotlin</artifactId>
25-
<version>0.0.1</version>
26+
<version>0.0.4</version>
2627
</dependency>
2728
```
2829

2930
To use via Gradle:
3031

3132
```kotlin
32-
implementation("earth.adi:typeid-kotlin:0.0.1")
33+
implementation("earth.adi:typeid-kotlin:0.0.4")
3334
```
3435

3536

@@ -46,7 +47,7 @@ To use the typed features of the library, you need to define your typed id assoc
4647

4748
```kotlin
4849
// Define your identifiable entity type:
49-
data class User(val id: UserId) // can contain other fields
50+
data class User(val id: UserId) // can contain other fields
5051

5152
// Define a typealias for the user id.
5253
typealias UserId = Id<out User>
@@ -185,22 +186,43 @@ val read = objectMapper.readValue<JsonUserAndOrganization>(writtenJson)
185186
```
186187

187188

188-
## Building From Source & Benchmarks
189+
## Building From Source
189190
<details>
190191
<summary>Details</summary>
191192

192193
```console
193194
~$ git clone https://github.com/aleris/typeid-kotlin.git
194195
~$ cd typeid-kotling
196+
~/typeid-kotlin sdk use java 17.0.9-tem
195197
~/typeid-kotlin ./gradlew build
196198
```
199+
</details>
200+
201+
202+
## Releasing
203+
<details>
204+
<summary>Details</summary>
205+
206+
```console
207+
~$ cd typeid-kotling
208+
~/typeid-kotlin ./gradlew jreleaserConfig
209+
~/typeid-kotlin ./gradlew clean
210+
~/typeid-kotlin ./gradlew publish
211+
~/typeid-kotlin ./gradlew jreleaserFullRelease
212+
```
213+
</details>
214+
215+
216+
## Benchmarks
217+
<details>
218+
<summary>Details</summary>
197219

198220
There is a small [JMH](https://github.com/openjdk/jmh) microbenchmark included:
199221
```console
200222
~/typeid-kotlin ./gradlew jmh
201223
```
202224

203-
In a single-threaded run, all operations perform in the range of millions of calls per second,
225+
In a single-threaded run, all operations perform in the range of millions of calls per second,
204226
which should be enough for most use cases (used setup: Eclipse Temurin 17 JDK, 2021 MacBook Pro).
205227

206228
| Benchmark | Mode | Cnt | Score | Error | Units |

build.gradle.kts

+93-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
22
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
33

44
plugins {
5+
`java-library`
56
alias(libs.plugins.kotlinJvm)
67
alias(libs.plugins.spotless)
78
jacoco
89
alias(libs.plugins.jmh)
10+
`maven-publish`
11+
alias(libs.plugins.jreleaser)
12+
alias(libs.plugins.dokka)
913
}
1014

1115
group = "earth.adi"
1216

13-
version = "0.0.3"
17+
version = "0.0.4"
1418

1519
repositories { mavenCentral() }
1620

@@ -25,7 +29,10 @@ dependencies {
2529

2630
kotlin { jvmToolchain(17) }
2731

28-
java { withSourcesJar() }
32+
java {
33+
withSourcesJar()
34+
withJavadocJar()
35+
}
2936

3037
tasks.withType<JavaCompile> { dependsOn(tasks.spotlessApply) }
3138

@@ -45,6 +52,11 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {
4552
}
4653
}
4754

55+
task<Exec>("updateReadmeVersion") {
56+
// mustRunAfter(tasks.build)
57+
commandLine("sh", "./scripts/updateReadmeVersion.sh")
58+
}
59+
4860
tasks.test {
4961
useJUnitPlatform()
5062
finalizedBy(tasks.jacocoTestReport, tasks.jacocoTestCoverageVerification)
@@ -82,7 +94,7 @@ tasks.jacocoTestReport { dependsOn(tasks.test) }
8294
tasks.jacocoTestCoverageVerification {
8395
dependsOn(tasks.jacocoTestReport)
8496

85-
violationRules { rule { limit { minimum = "1".toBigDecimal() } } }
97+
violationRules { rule { limit { minimum = "1.00".toBigDecimal() } } }
8698
}
8799

88100
jmh {
@@ -91,3 +103,81 @@ jmh {
91103
threads.set(1)
92104
fork.set(2)
93105
}
106+
107+
val mavenArtifactId: String by project
108+
val mavenArtifactDescription: String by project
109+
110+
tasks.jar {
111+
manifest {
112+
attributes(
113+
mapOf(
114+
"Implementation-Title" to mavenArtifactId, "Implementation-Version" to project.version))
115+
}
116+
}
117+
118+
val stagingDir: Provider<Directory> = layout.buildDirectory.dir("staging-deploy")
119+
120+
publishing {
121+
publications {
122+
create<MavenPublication>("mavenJava") {
123+
artifactId = mavenArtifactId
124+
from(components["java"])
125+
pom {
126+
name.set(mavenArtifactId)
127+
description.set(mavenArtifactDescription)
128+
url.set("https://github.com/aleris/typeid-kotlin")
129+
licenses {
130+
license {
131+
name.set("The Apache License, Version 2.0")
132+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
133+
}
134+
}
135+
developers {
136+
developer {
137+
id.set("aleris")
138+
name.set("Adrian Tosca")
139+
email.set("adrian.tosca@gmail.com")
140+
}
141+
}
142+
scm {
143+
connection.set("scm:git:git@github.com:aleris/typeid-kotlin.git")
144+
developerConnection.set("scm:git:git@github.com:aleris/typeid-kotlin.git")
145+
url.set("https://github.com/aleris/typeid-kotlin/")
146+
}
147+
}
148+
}
149+
}
150+
repositories { maven { url = stagingDir.get().asFile.toURI() } }
151+
}
152+
153+
tasks.publish { dependsOn(tasks.dokkaJekyll) }
154+
155+
jreleaser {
156+
project {
157+
description.set(mavenArtifactDescription)
158+
authors.set(arrayListOf("aleris"))
159+
license.set("Apache-2.0")
160+
inceptionYear = "2024"
161+
}
162+
release {
163+
github {
164+
repoOwner.set("aleris")
165+
overwrite = true
166+
}
167+
}
168+
signing {
169+
active.set(org.jreleaser.model.Active.ALWAYS)
170+
armored = true
171+
}
172+
deploy {
173+
maven {
174+
mavenCentral {
175+
register("sonatype") {
176+
active.set(org.jreleaser.model.Active.ALWAYS)
177+
url.set("https://central.sonatype.com/api/v1/publisher")
178+
stagingRepository(stagingDir.get().toString())
179+
}
180+
}
181+
}
182+
}
183+
}

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
kotlin.code.style=official
2+
mavenArtifactId=typeid-kotlin
3+
mavenArtifactDescription=A type-safe TypeID implementation for Kotlin

gradle/libs.versions.toml

+4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ junit = "5.10.2"
77
assertj = "3.25.3"
88
jmh = "0.7.2"
99
jqwik = "1.8.4"
10+
jreleaser = "1.12.0"
11+
dokka = "1.9.20"
1012

1113
[plugins]
1214
jmh = { id = "me.champeau.jmh", version.ref = "jmh" }
1315
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
1416
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
17+
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
18+
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
1519

1620
[libraries]
1721
javaUuidGenerator = { module = "com.fasterxml.uuid:java-uuid-generator", version.ref = "javaUuidGenerator" }

scripts/updateReadmeVersion.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
# Replace the version in README.md with the version from build.gradle.kts
4+
# Usage:
5+
# ./scripts/updateReadmeVersion.sh
6+
7+
SED="sed"
8+
if ! command -v gsed &> /dev/null
9+
then
10+
# brew install gnu-sed
11+
SED="gsed"
12+
fi
13+
14+
VERSION=$(SED -n 's/^version\s*=\s*"\([0-9]\.[0-9]\.[0-9]\)"/\1/p' < build.gradle.kts)
15+
16+
echo "Updating to version $VERSION in README.md..."
17+
SED -i -E 's/earth\.adi:typeid-kotlin:[0-9]+\.[0-9]+\.[0-9]+/earth\.adi:typeid-kotlin:'"${VERSION}"'/' README.md
18+
SED -i -E 's|<version>[0-9]+\.[0-9]+\.[0-9]+|<version>'"${VERSION}"'|' README.md
19+
SED -i -E 's/Version-[0-9]+\.[0-9]+\.[0-9]+-blue/Version-'"${VERSION}"'-blue/' README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package earth.adi;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package earth.adi.typeid;
2+
3+
/**
4+
* JavaType.
5+
*/
6+
public class JavaType {
7+
public static JavaType of(Class<?> clazz) {
8+
return new JavaType(clazz);
9+
}
10+
11+
private final Class<?> clazz;
12+
13+
private JavaType(Class<?> clazz) {
14+
this.clazz = clazz;
15+
}
16+
17+
public Class<?> getClazz() {
18+
return clazz;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* TypeID package.
3+
*/
4+
package earth.adi.typeid;

src/main/java/earth/package-info.java

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package earth;

src/main/kotlin/module-info.java src/main/java/module-info.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* TypeId Module.
3+
*/
14
module earth.adi.typeid {
25
requires com.fasterxml.uuid;
36
requires com.fasterxml.jackson.databind;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package earth.adi.typeid
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.junit.jupiter.api.Test
5+
6+
internal class JavaTypeTest {
7+
@Test
8+
fun of() {
9+
val javaType = JavaType.of(String::class.java)
10+
assertThat(javaType.clazz).isEqualTo(String::class.java)
11+
}
12+
13+
@Test
14+
fun get() {
15+
val javaType = JavaType.of(String::class.java)
16+
assertThat(javaType.clazz).isEqualTo(String::class.java)
17+
}
18+
}

0 commit comments

Comments
 (0)