Skip to content

Commit

Permalink
Fix build dependencies between 'core' and 'faker' modules
Browse files Browse the repository at this point in the history
The f*ing thing was driving me crazy... Why did I ever make
:core:integrationTest depend on :faker:XXX:shadowJar?..

Also made 'faker' modules depend on implementation of 'core' project
rather than having compileOnly.
The latter doesn't seems to work when using e.g. `kotlin-faker:2.0.0-rc.2`
and `kotlin-faker-books:2.0.0-rc.1`
  • Loading branch information
serpro69 committed Mar 10, 2024
1 parent 55a678a commit 455ea5e
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 57 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ val shadowJar by tasks.getting(ShadowJar::class) {
from("${rootProject.rootDir.resolve("LICENSE.adoc")}") {
into("META-INF")
}
dependsOn(integrationTest)
dependsOn(tasks.jar)
}

Expand Down
22 changes: 11 additions & 11 deletions buildSrc/src/main/kotlin/faker-provider-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
}

dependencies {
val compileOnly by configurations
val testImplementation by configurations
// In order to use an additional fake data provider,
// core faker needs to be on the classpath.
// Don't add it as transitive dependency to each faker provider
compileOnly(project(":core"))
// we need implementation dependency for tests to be able to access 'core' functionality
testImplementation(project(":core"))
val implementation by configurations
implementation(project(":core"))
}

// since we're adding :core as testImplementation dependency,
// since we're adding :core as implementation dependency,
// we also need to make sure ShadowJar tasks depend on core having been built
val shadowJar by tasks.getting(ShadowJar::class) {
dependsOn(":core:assemble")
}

// since we're adding :core as implementation dependency, and effectively testImplementation
// we also need to make sure Test tasks depend on core having been built
tasks.withType<Test> {
dependsOn(":core:shadowJar")
dependsOn(":core:assemble")
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import kotlin.system.exitProcess
"see https://github.com/serpro69/kotlin-faker/README.md for more installation and usage examples"
],
version = [
"faker: {FAKER_VER}", // {FAKER_VER} is a placeholder that will be temporarily replaced during compilation
"faker-bot: {FAKER_VER}",
"faker: 0.0.0", // 0.0.0 is a placeholder that will be temporarily replaced during compilation
"faker-bot: 0.0.0",
"Built with picocli ${CommandLine.VERSION}",
"JVM: \${java.version} (\${java.vendor} \${java.vm.name} \${java.vm.version})",
"OS: \${os.name} \${os.version} \${os.arch}"
Expand Down
13 changes: 0 additions & 13 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.3")
shadow("com.ibm.icu:icu4j:73.2")
shadow("com.github.mifmif:generex:1.0.2")
// integration dependencies for classes in docs package, e.g. Homepage.kt
// NB! only add fakers that are needed
val integrationImplementation by configurations
integrationImplementation(project(":faker:commerce"))
integrationImplementation(project(":faker:movies"))
integrationImplementation(project(":faker:tvshows"))
}

// integrationTest task must run after we've built the dependencies
tasks.getByName("integrationTest") {
dependsOn(":faker:commerce:shadowJar")
dependsOn(":faker:movies:shadowJar")
dependsOn(":faker:tvshows:shadowJar")
}

apply<Yaml2JsonPlugin>() // this shouldn't really be needed since the plugin is supposed to be applied in the plugins{} block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
package io.github.serpro69.kfaker.docs

import io.github.serpro69.kfaker.Faker
import io.github.serpro69.kfaker.commerce.CommerceFaker
import io.github.serpro69.kfaker.fakerConfig
import io.github.serpro69.kfaker.movies.MoviesFaker
import io.github.serpro69.kfaker.tv.TvShowsFaker
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import org.junit.jupiter.api.Assertions.assertEquals
Expand Down Expand Up @@ -43,33 +40,13 @@ class Homepage : DescribeSpec({
faker.address.streetAddress() // => 474 Kilback Manor
// END data_provider_two
}
it("should print a SWIFT BIC code") {
// START data_provider_four
CommerceFaker().bank.swiftBic() // => AACCGB21
// END data_provider_four
}
it("should print a safe email address") {
// START data_provider_three
faker.internet.safeEmail() // => [email protected]
// END data_provider_three
}
it("should print a ship name from The Expanse") {
// START data_provider_five
TvShowsFaker().theExpanse.ships() // => Rocinante
// END data_provider_five
}
it("should print a Star Wars character name") {
// START data_provider_six_a
MoviesFaker().starWars.characters() // => Darth Vader
// END data_provider_six_a
}
it("should print a character name from Friends") {
// START data_provider_six_b
TvShowsFaker().friends.characters() // => Phoebe Buffay
// END data_provider_six_b
}
// START data_provider_seven
// a total of 171 different data providers
// a total of 213 different data providers
// END data_provider_seven
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ internal class FakerServiceTest : DescribeSpec({

assertSoftly {
resolvedValue.split(" ") shouldHaveAtLeastSize 2
resolvedValue.split(" ") shouldHaveAtMostSize 3
// prefix 'The Hon.' is single value,
// but will be split into two strings and will result in size 4
resolvedValue.split(" ") shouldHaveAtMostSize 4
resolvedValue shouldNotContain Regex("""#\{\p{all}+?}""")
}
}
Expand Down
4 changes: 4 additions & 0 deletions docs/src/orchid/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ snippets:
baseDirs:
- '../../../../core/src/main/resources/locales/en/'
- '../../../../core/src/integration/kotlin/'
- '../../../../faker/books/src/integration/kotlin/'
- '../../../../faker/commerce/src/integration/kotlin/'
- '../../../../faker/movies/src/integration/kotlin/'
- '../../../../faker/tvshows/src/integration/kotlin/'
- '../../../../core/src/integration/java/'
- 'snippets'
recursive: true
Expand Down
8 changes: 4 additions & 4 deletions docs/src/orchid/resources/data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ homepageSections:
snippets: ['data_provider_three']
lang: 'kotlin'
- title: 'Banking'
snippets: ['data_provider_four']
snippets: ['commerce_faker_one']
lang: 'kotlin'
- title: 'Books'
snippets: ['data_provider_five']
snippets: ['books_faker_one']
lang: 'kotlin'
- title: 'Movies and TV'
snippets: ['data_provider_six_a', 'data_provider_six_b']
snippets: ['movies_faker_one', 'tvshows_faker_one']
lang: 'kotlin'
- title: '…and many others'
snippets: ['data_provider_seven']
lang: 'kotlin'
- title: '…in 57 locales:'
- title: '…in 60 locales:'
snippets: ['faker_locale_zero']
lang: 'kotlin'
tabs:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/orchid/resources/pages/faker-comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fun main() {
</tr>
<tr>
<td>{{ anchor(title='Available Data Providers', collectionType='wiki', collectionId='', itemId='Data Providers') }} (<code>address</code>, <code>name</code>, etc.)</td>
<td>197</td>
<td>213</td>
<td><a href="https://github.com/datafaker-net/datafaker/blob/a3f8509537e2c9eb0c2e28daa416cc4c1bb8a3fa/README.md?plain=1#L154-L268">115</a></td>
<td>73</td>
<td>8</td>
Expand All @@ -103,7 +103,7 @@ fun main() {
</tr>
<tr>
<td>{{ anchor(title='Available Locales', collectionType='wiki', collectionId='', itemId='Available Locales') }} (<code>nb-NO</code>, <code>uk</code>, <code>es</code> etc.)</td>
<td>58</td>
<td>60</td>
<td><a href="https://github.com/datafaker-net/datafaker/blob/a3f8509537e2c9eb0c2e28daa416cc4c1bb8a3fa/README.md?plain=1#L285-L335">51</a></td>
<td>47</td>
<td>10</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.serpro69.kfaker.books.docs

import io.github.serpro69.kfaker.books.BooksFaker
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import java.util.*

/**
* Documentation code snippets for the docs website homepage.
*
* This approach has the benefit over using something like code-blocks in .md files directly in a way
* that this becomes a "live-documentation",
* and additionally it's also being tested since this is, after all, a test class.
*
* Usage:
* ❶ Wrap each code snippet in comments like `// START snippet_name` and `// END snippet_name`
* ❷ Code snippets can be referenced from the docs using the {% snippet snippet_name %} tag.
* ❸ (See https://orchid.run/plugins/orchidsnippets for snippets docs)
*/
@DisplayName("Snippets used in Orchid docs 'homepage'")
class Homepage : DescribeSpec({
describe("BooksFaker") {
context("Fake Data Providers in Books domain") {
it("should print a book genre") {
// START books_faker_one
val faker = BooksFaker()
faker.book.genre() // => Fantasy
// END books_faker_one
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.serpro69.kfaker.commerce.docs

import io.github.serpro69.kfaker.commerce.CommerceFaker
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import java.util.*

/**
* Documentation code snippets for the docs website homepage.
*
* This approach has the benefit over using something like code-blocks in .md files directly in a way
* that this becomes a "live-documentation",
* and additionally it's also being tested since this is, after all, a test class.
*
* Usage:
* ❶ Wrap each code snippet in comments like `// START snippet_name` and `// END snippet_name`
* ❷ Code snippets can be referenced from the docs using the {% snippet snippet_name %} tag.
* ❸ (See https://orchid.run/plugins/orchidsnippets for snippets docs)
*/
@DisplayName("Snippets used in Orchid docs 'homepage'")
class Homepage : DescribeSpec({
describe("CommerceFaker") {
context("Fake Data Providers in Commerce domain") {
it("should print a SWIFT BIC code") {
// START commerce_faker_one
val faker = CommerceFaker()
faker.bank.swiftBic() // => AACCGB21
// END commerce_faker_one
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.serpro69.kfaker.movies.docs

import io.github.serpro69.kfaker.movies.MoviesFaker
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import java.util.*

/**
* Documentation code snippets for the docs website homepage.
*
* This approach has the benefit over using something like code-blocks in .md files directly in a way
* that this becomes a "live-documentation",
* and additionally it's also being tested since this is, after all, a test class.
*
* Usage:
* ❶ Wrap each code snippet in comments like `// START snippet_name` and `// END snippet_name`
* ❷ Code snippets can be referenced from the docs using the {% snippet snippet_name %} tag.
* ❸ (See https://orchid.run/plugins/orchidsnippets for snippets docs)
*/
@DisplayName("Snippets used in Orchid docs 'homepage'")
class Homepage : DescribeSpec({
describe("MoviesFaker") {
context("Fake Data Providers in Movies domain") {
it("should print a Star Wars character name") {
// START movies_faker_one
val faker = MoviesFaker()
faker.starWars.characters() // => Darth Vader
// END movies_faker_one
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.serpro69.kfaker.tv.docs

import io.github.serpro69.kfaker.tv.TvShowsFaker
import io.kotest.core.spec.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import java.util.*

/**
* Documentation code snippets for the docs website homepage.
*
* This approach has the benefit over using something like code-blocks in .md files directly in a way
* that this becomes a "live-documentation",
* and additionally it's also being tested since this is, after all, a test class.
*
* Usage:
* ❶ Wrap each code snippet in comments like `// START snippet_name` and `// END snippet_name`
* ❷ Code snippets can be referenced from the docs using the {% snippet snippet_name %} tag.
* ❸ (See https://orchid.run/plugins/orchidsnippets for snippets docs)
*/
@DisplayName("Snippets used in Orchid docs 'homepage'")
class Homepage : DescribeSpec({
describe("TvShowsFaker") {
context("Fake Data Providers in TvShows domain") {
it("should print a character name from Friends") {
// START tvshows_faker_one
val faker = TvShowsFaker()
faker.friends.characters() // => Phoebe Buffay
// END tvshows_faker_one
}
}
}
})

0 comments on commit 455ea5e

Please sign in to comment.