Skip to content

Commit

Permalink
Update publishing section
Browse files Browse the repository at this point in the history
  • Loading branch information
anod committed Aug 12, 2023
1 parent 9940217 commit 277fd06
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# ksp-dotenv
Gradle KSP Multiplatform plugin to generate code from .env file

# Running example
# Example

`./gradlew example:run`

# Setup

1. Include "com.google.devtools.ksp" in case it's wasnt in the project yet
2. Update build.gradle.kts
1. Include [com.google.devtools.ksp](https://kotlinlang.org/docs/ksp-quickstart.html) in case it wasn't in the project yet
2. Add GitHup package repository following instructions https://github.com/anod/ksp-dotenv/packages/1921207
3. Add dependencies to build.gradle.kts
```kotlin
dependencies {
add("kspCommonMainMetadata", "info.anodsplace.dotenv")
add("kspJvm", project("info.anodsplace.dotenv"))
add("kspCommonMainMetadata", "info.anodsplace.dotenv:ksp-dotenv-jvm:$kspDotenvVersion")
add("kspJvm", project("info.anodsplace.dotenv:ksp-dotenv-jvm:$kspDotenvVersion"))
}

```
4. Configure the plugin inside build.gradle.kts
````
ksp {
arg("info.anodsplace.dotenv.path", project.rootDir.toString())
arg("info.anodsplace.dotenv.filename", "env.example") // default ".env"
Expand All @@ -24,9 +27,17 @@ Gradle KSP Multiplatform plugin to generate code from .env file
arg("info.anodsplace.dotenv.class", "DotEnvExample")
}
```
3. Use generated file
5. Build & use generated file
```kotlin
println("[ksp-dotenv] ENDPOINT_FE=${DotEnvExample.endpointFe}")
println("[ksp-dotenv] ENDPOINT_BE=${DotEnvExample.endpointBe}")
println("[ksp-dotenv] ENV=${DotEnvExample.env}")
```
```

# Publish

`./gradlew publish`

# Author

Alexandr Gavrishev, 2023
53 changes: 53 additions & 0 deletions ksp-dotenv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version = "0.1.0"

kotlin {
jvm()

sourceSets {
val jvmMain by getting {
dependencies {
Expand All @@ -22,4 +23,56 @@ kotlin {
resources.srcDir("src/main/resources")
}
}
val publicationsFromMainHost = listOf(jvm()).map { it.name } + "kotlinMultiplatform"
publishing {
publications {
matching { it.name in publicationsFromMainHost }.all {
val targetPublication = this@all
tasks.withType<AbstractPublishToMaven>()
.matching { it.publication == targetPublication }
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
}
}
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/anod/ksp-dotenv")
credentials {
username = project.findProperty("GITHUB_USER") as? String ?: System.getenv("GITHUB_USER")
password = project.findProperty("GITHUB_TOKEN") as? String ?: System.getenv("GITHUB_TOKEN")
}
}
}
publications {
register<MavenPublication>("github") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
pom {
description.set(
"Gradle KSP Multiplatform plugin to generate code from .env file")
name.set(project.name)
url.set("https://github.com/anod/ksp-dotenv.git")
licenses {
license {
name.set("MIT License")
url.set("https://github.com/anod/ksp-dotenv/blob/main/LICENSE")
distribution.set("repo")
}
}
developers {
developer {
id.set("anodsplace.info")
name.set("Alexandr Gavrishev")
email.set("alex.gavrishev@gmail.com")
}
}
scm { url.set("scm:git:git@github.com:facebook/yoga.git") }
}
}
}
}
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pluginManagement {
kotlin("multiplatform") version kotlinVersion apply false
}
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
Expand All @@ -16,7 +15,6 @@ dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
mavenLocal()
}
}

Expand Down

0 comments on commit 277fd06

Please sign in to comment.