Skip to content

Commit

Permalink
publish project
Browse files Browse the repository at this point in the history
  • Loading branch information
reifiedbeans committed Oct 5, 2024
0 parents commit 8c087f8
Show file tree
Hide file tree
Showing 22 changed files with 909 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_code_style = intellij_idea
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Gradle
.gradle/
build/

# JetBrains
.idea/
*.iml

# macOS
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Drew Davis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Kava

[![maven central](https://img.shields.io/maven-central/v/dev.reifiedbeans/kava
)](https://central.sonatype.com/artifact/dev.reifiedbeans/kava)
[![license: MIT](https://img.shields.io/github/license/reifiedbeans/kava
)](https://github.com/reifiedbeans/kava/blob/main/LICENSE)

An easy-to-use Kotlin DSL for building modules with the Guice dependency injection framework.

```kotlin
import dev.reifiedbeans.kava.getInstance
import dev.reifiedbeans.kava.kava

data class Message(val content: String)

fun main() {
val module = kava {
provide(Message::class) { Message("Hello, world!") }
}

val message = module.injector.getInstance(Message::class)
println(message.content)
}
```

## License

Licensed under the [MIT License](https://github.com/reifiedbeans/kava/blob/main/LICENSE).

[guice]: https://github.com/google/guice
45 changes: 45 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlin)

alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}

allprojects {
group = "dev.reifiedbeans"
version = "1.0.0"

repositories {
mavenCentral()
}
}

subprojects {
apply(plugin = "jacoco")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "org.jlleitschuh.gradle.ktlint")

java {
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

tasks.named<Test>("test") {
useJUnitPlatform()
finalizedBy("jacocoTestReport")
}

tasks.named<JacocoReport>("jacocoTestReport") {
reports {
xml.required = true
}
}
}
4 changes: 4 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation(project(":kava"))
implementation(libs.jakarta.inject)
}
35 changes: 35 additions & 0 deletions examples/src/main/kotlin/SimpleApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import dev.reifiedbeans.kava.getInstance
import dev.reifiedbeans.kava.kava
import jakarta.inject.Inject
import jakarta.inject.Named

private const val SPECIAL_MESSAGE = "SPECIAL_MESSAGE"

interface Messenger {
fun sendMessage(message: String)
}

class StandardMessenger : Messenger {
override fun sendMessage(message: String) {
println(message)
}
}

class SimpleApplication @Inject constructor(
private val messenger: Messenger,
@Named(SPECIAL_MESSAGE) private val message: String,
) {
fun start() {
messenger.sendMessage(message)
}
}

fun main() {
val module = kava {
bind { Messenger::class to StandardMessenger::class }
provide(String::class, name = SPECIAL_MESSAGE) { "Hello, world!" }
}

val app = module.injector.getInstance(SimpleApplication::class)
app.start()
}
23 changes: 23 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[versions]
detekt = "1.23.7"
dokka = "1.9.20"
guice = "7.0.0"
jakarta-inject = "2.0.1"
junit = "5.11.1"
kotlin = "2.0.20"
ktlint-gradle = "12.1.1"
mockk = "1.13.12"

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-gradle" }

[libraries]
dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka" }
guice = { module = "com.google.inject:guice", version.ref = "guice" }
jakarta-inject = { module = "jakarta.inject:jakarta.inject-api", version.ref = "jakarta-inject" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 8c087f8

Please sign in to comment.