Skip to content

Commit 8c087f8

Browse files
committed
publish project
0 parents  commit 8c087f8

22 files changed

Lines changed: 909 additions & 0 deletions

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.{kt,kts}]
2+
ktlint_code_style = intellij_idea

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Gradle
2+
.gradle/
3+
build/
4+
5+
# JetBrains
6+
.idea/
7+
*.iml
8+
9+
# macOS
10+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Drew Davis
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Kava
2+
3+
[![maven central](https://img.shields.io/maven-central/v/dev.reifiedbeans/kava
4+
)](https://central.sonatype.com/artifact/dev.reifiedbeans/kava)
5+
[![license: MIT](https://img.shields.io/github/license/reifiedbeans/kava
6+
)](https://github.com/reifiedbeans/kava/blob/main/LICENSE)
7+
8+
An easy-to-use Kotlin DSL for building modules with the Guice dependency injection framework.
9+
10+
```kotlin
11+
import dev.reifiedbeans.kava.getInstance
12+
import dev.reifiedbeans.kava.kava
13+
14+
data class Message(val content: String)
15+
16+
fun main() {
17+
val module = kava {
18+
provide(Message::class) { Message("Hello, world!") }
19+
}
20+
21+
val message = module.injector.getInstance(Message::class)
22+
println(message.content)
23+
}
24+
```
25+
26+
## License
27+
28+
Licensed under the [MIT License](https://github.com/reifiedbeans/kava/blob/main/LICENSE).
29+
30+
[guice]: https://github.com/google/guice

build.gradle.kts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
plugins {
4+
alias(libs.plugins.kotlin)
5+
6+
alias(libs.plugins.detekt)
7+
alias(libs.plugins.ktlint)
8+
}
9+
10+
allprojects {
11+
group = "dev.reifiedbeans"
12+
version = "1.0.0"
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
}
18+
19+
subprojects {
20+
apply(plugin = "jacoco")
21+
apply(plugin = "org.jetbrains.kotlin.jvm")
22+
apply(plugin = "io.gitlab.arturbosch.detekt")
23+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
24+
25+
java {
26+
targetCompatibility = JavaVersion.VERSION_1_8
27+
}
28+
29+
kotlin {
30+
compilerOptions {
31+
jvmTarget.set(JvmTarget.JVM_1_8)
32+
}
33+
}
34+
35+
tasks.named<Test>("test") {
36+
useJUnitPlatform()
37+
finalizedBy("jacocoTestReport")
38+
}
39+
40+
tasks.named<JacocoReport>("jacocoTestReport") {
41+
reports {
42+
xml.required = true
43+
}
44+
}
45+
}

examples/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dependencies {
2+
implementation(project(":kava"))
3+
implementation(libs.jakarta.inject)
4+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import dev.reifiedbeans.kava.getInstance
2+
import dev.reifiedbeans.kava.kava
3+
import jakarta.inject.Inject
4+
import jakarta.inject.Named
5+
6+
private const val SPECIAL_MESSAGE = "SPECIAL_MESSAGE"
7+
8+
interface Messenger {
9+
fun sendMessage(message: String)
10+
}
11+
12+
class StandardMessenger : Messenger {
13+
override fun sendMessage(message: String) {
14+
println(message)
15+
}
16+
}
17+
18+
class SimpleApplication @Inject constructor(
19+
private val messenger: Messenger,
20+
@Named(SPECIAL_MESSAGE) private val message: String,
21+
) {
22+
fun start() {
23+
messenger.sendMessage(message)
24+
}
25+
}
26+
27+
fun main() {
28+
val module = kava {
29+
bind { Messenger::class to StandardMessenger::class }
30+
provide(String::class, name = SPECIAL_MESSAGE) { "Hello, world!" }
31+
}
32+
33+
val app = module.injector.getInstance(SimpleApplication::class)
34+
app.start()
35+
}

gradle/libs.versions.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[versions]
2+
detekt = "1.23.7"
3+
dokka = "1.9.20"
4+
guice = "7.0.0"
5+
jakarta-inject = "2.0.1"
6+
junit = "5.11.1"
7+
kotlin = "2.0.20"
8+
ktlint-gradle = "12.1.1"
9+
mockk = "1.13.12"
10+
11+
[plugins]
12+
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
13+
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
14+
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
15+
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-gradle" }
16+
17+
[libraries]
18+
dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka" }
19+
guice = { module = "com.google.inject:guice", version.ref = "guice" }
20+
jakarta-inject = { module = "jakarta.inject:jakarta.inject-api", version.ref = "jakarta-inject" }
21+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
22+
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
23+
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }

gradle/wrapper/gradle-wrapper.jar

42.6 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)