Skip to content

Commit

Permalink
publish configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Tosca committed May 17, 2024
1 parent 92039b3 commit 80ce5b2
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 13 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ jobs:
java-version: 17
- uses: gradle/actions/setup-gradle@v3
- run: ./gradlew build
- run: ./gradlew publishAllPublicationsToOSSRHRepository
- run: ./gradlew jreleaserFullRelease
env:
ORG_GRADLE_PROJECT_OSSRHUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_OSSRHPassword: ${{ secrets.OSSRH_TOKEN }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
ENV: "CI"
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.JRELEASER_MAVENCENTRAL_TOKEN }}
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# typeid-kotlin
![Build Status](https://github.com/aleris/typeid-kotlin/actions/workflows/build-on-push.yml/badge.svg)
![Current Version](https://img.shields.io/badge/Version-0.0.4-blue)


## A Kotlin implementation of [TypeID](https://github.com/jetpack-io/typeid).
Expand All @@ -22,14 +23,14 @@ To use with Maven:
<dependency>
<groupId>earth.adi</groupId>
<artifactId>typeid-kotlin</artifactId>
<version>0.0.1</version>
<version>0.0.4</version>
</dependency>
```

To use via Gradle:

```kotlin
implementation("earth.adi:typeid-kotlin:0.0.1")
implementation("earth.adi:typeid-kotlin:0.0.4")
```


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

```kotlin
// Define your identifiable entity type:
data class User(val id: UserId) // can contain other fields
data class User(val id: UserId) // can contain other fields

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


## Building From Source & Benchmarks
## Building From Source
<details>
<summary>Details</summary>

```console
~$ git clone https://github.com/aleris/typeid-kotlin.git
~$ cd typeid-kotling
~/typeid-kotlin sdk use java 17.0.9-tem
~/typeid-kotlin ./gradlew build
```
</details>


## Releasing
<details>
<summary>Details</summary>

```console
~$ cd typeid-kotling
~/typeid-kotlin ./gradlew jreleaserConfig
~/typeid-kotlin ./gradlew clean
~/typeid-kotlin ./gradlew publish
~/typeid-kotlin ./gradlew jreleaserFullRelease
```
</details>


## Benchmarks
<details>
<summary>Details</summary>

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

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

| Benchmark | Mode | Cnt | Score | Error | Units |
Expand Down
96 changes: 93 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.*

plugins {
`java-library`
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.spotless)
jacoco
alias(libs.plugins.jmh)
`maven-publish`
alias(libs.plugins.jreleaser)
alias(libs.plugins.dokka)
}

group = "earth.adi"

version = "0.0.3"
version = "0.0.4"

repositories { mavenCentral() }

Expand All @@ -25,7 +29,10 @@ dependencies {

kotlin { jvmToolchain(17) }

java { withSourcesJar() }
java {
withSourcesJar()
withJavadocJar()
}

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

Expand All @@ -45,6 +52,11 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {
}
}

task<Exec>("updateReadmeVersion") {
// mustRunAfter(tasks.build)
commandLine("sh", "./scripts/updateReadmeVersion.sh")
}

tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport, tasks.jacocoTestCoverageVerification)
Expand Down Expand Up @@ -82,7 +94,7 @@ tasks.jacocoTestReport { dependsOn(tasks.test) }
tasks.jacocoTestCoverageVerification {
dependsOn(tasks.jacocoTestReport)

violationRules { rule { limit { minimum = "1".toBigDecimal() } } }
violationRules { rule { limit { minimum = "1.00".toBigDecimal() } } }
}

jmh {
Expand All @@ -91,3 +103,81 @@ jmh {
threads.set(1)
fork.set(2)
}

val mavenArtifactId: String by project
val mavenArtifactDescription: String by project

tasks.jar {
manifest {
attributes(
mapOf(
"Implementation-Title" to mavenArtifactId, "Implementation-Version" to project.version))
}
}

val stagingDir: Provider<Directory> = layout.buildDirectory.dir("staging-deploy")

publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = mavenArtifactId
from(components["java"])
pom {
name.set(mavenArtifactId)
description.set(mavenArtifactDescription)
url.set("https://github.com/aleris/typeid-kotlin")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("aleris")
name.set("Adrian Tosca")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:[email protected]:aleris/typeid-kotlin.git")
developerConnection.set("scm:git:[email protected]:aleris/typeid-kotlin.git")
url.set("https://github.com/aleris/typeid-kotlin/")
}
}
}
}
repositories { maven { url = stagingDir.get().asFile.toURI() } }
}

tasks.publish { dependsOn(tasks.dokkaJekyll) }

jreleaser {
project {
description.set(mavenArtifactDescription)
authors.set(arrayListOf("aleris"))
license.set("Apache-2.0")
inceptionYear = "2024"
}
release {
github {
repoOwner.set("aleris")
overwrite = true
}
}
signing {
active.set(org.jreleaser.model.Active.ALWAYS)
armored = true
}
deploy {
maven {
mavenCentral {
register("sonatype") {
active.set(org.jreleaser.model.Active.ALWAYS)
url.set("https://central.sonatype.com/api/v1/publisher")
stagingRepository(stagingDir.get().toString())
}
}
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
kotlin.code.style=official
mavenArtifactId=typeid-kotlin
mavenArtifactDescription=A type-safe TypeID implementation for Kotlin
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ junit = "5.10.2"
assertj = "3.25.3"
jmh = "0.7.2"
jqwik = "1.8.4"
jreleaser = "1.12.0"
dokka = "1.9.20"

[plugins]
jmh = { id = "me.champeau.jmh", version.ref = "jmh" }
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }

[libraries]
javaUuidGenerator = { module = "com.fasterxml.uuid:java-uuid-generator", version.ref = "javaUuidGenerator" }
Expand Down
19 changes: 19 additions & 0 deletions scripts/updateReadmeVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# Replace the version in README.md with the version from build.gradle.kts
# Usage:
# ./scripts/updateReadmeVersion.sh

SED="sed"
if ! command -v gsed &> /dev/null
then
# brew install gnu-sed
SED="gsed"
fi

VERSION=$(SED -n 's/^version\s*=\s*"\([0-9]\.[0-9]\.[0-9]\)"/\1/p' < build.gradle.kts)

echo "Updating to version $VERSION in README.md..."
SED -i -E 's/earth\.adi:typeid-kotlin:[0-9]+\.[0-9]+\.[0-9]+/earth\.adi:typeid-kotlin:'"${VERSION}"'/' README.md
SED -i -E 's|<version>[0-9]+\.[0-9]+\.[0-9]+|<version>'"${VERSION}"'|' README.md
SED -i -E 's/Version-[0-9]+\.[0-9]+\.[0-9]+-blue/Version-'"${VERSION}"'-blue/' README.md
1 change: 1 addition & 0 deletions src/main/java/earth/adi/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package earth.adi;
20 changes: 20 additions & 0 deletions src/main/java/earth/adi/typeid/JavaType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package earth.adi.typeid;

/**
* JavaType.
*/
public class JavaType {
public static JavaType of(Class<?> clazz) {
return new JavaType(clazz);
}

private final Class<?> clazz;

private JavaType(Class<?> clazz) {
this.clazz = clazz;
}

public Class<?> getClazz() {
return clazz;
}
}
4 changes: 4 additions & 0 deletions src/main/java/earth/adi/typeid/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* TypeID package.
*/
package earth.adi.typeid;
1 change: 1 addition & 0 deletions src/main/java/earth/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package earth;
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* TypeId Module.
*/
module earth.adi.typeid {
requires com.fasterxml.uuid;
requires com.fasterxml.jackson.databind;
Expand Down
18 changes: 18 additions & 0 deletions src/test/kotlin/earth/adi/typeid/JavaTypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package earth.adi.typeid

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class JavaTypeTest {
@Test
fun of() {
val javaType = JavaType.of(String::class.java)
assertThat(javaType.clazz).isEqualTo(String::class.java)
}

@Test
fun get() {
val javaType = JavaType.of(String::class.java)
assertThat(javaType.clazz).isEqualTo(String::class.java)
}
}

0 comments on commit 80ce5b2

Please sign in to comment.