Description
This issue describes breaking changes that are coming in the next major version of kotlin-faker for easier migration.
Note that this issue serves for informational purposes only, and hence the conversation will be locked. If you've started using the new version of faker and face any problems or have any suggestions - please open a new issue.
Multi-Faker Implementation
Currently, the most notable change is described in #217 and implemented in #219 , which can break compilation for many calls to Faker
.
In short, if you've been using a lot of different data providers from Faker
, it is likely that some of them won't be there anymore in the "core faker" implementation. This includes data providers in the domains like books, tv shows, movies, music, sports and many others.
To keep using those, you will need to add one or more extra fakers via new dependencies and fix the imports and add new faker objects to access those providers.
Below is the list of all available fakers' dependencies (note that the default faker is needed for others to work as they won't pull it as a transitive dependency):
implementation("io.github.serpro69:kotlin-faker:2.0.0-rc.1") // NB! this is always needed
implementation("io.github.serpro69:kotlin-faker-books:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-commerce:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-creatures:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-edu:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-games:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-humor:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-japmedia:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-lorem:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-misc:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-movies:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-music:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-sports:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-tech:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-travel:2.0.0-rc.1")
implementation("io.github.serpro69:kotlin-faker-tvshows:2.0.0-rc.1")
If you have been using faker {}
dsl function to create instances of Faker
, each faker implementation also has such a function with the same name. Mind the package names though if using multiple ones in the same file.
Below is a simple example of using all the available fakers:
import io.github.serpro69.kfaker.faker
import io.github.serpro69.kfaker.books.faker as books
import io.github.serpro69.kfaker.commerce.faker as commerce
import io.github.serpro69.kfaker.creatures.faker as creatures
import io.github.serpro69.kfaker.edu.faker as edu
import io.github.serpro69.kfaker.games.faker as games
import io.github.serpro69.kfaker.humor.faker as humor
import io.github.serpro69.kfaker.japmedia.faker as japmedia
import io.github.serpro69.kfaker.lorem.faker as lorem
import io.github.serpro69.kfaker.misc.faker as misc
import io.github.serpro69.kfaker.movies.faker as movies
import io.github.serpro69.kfaker.music.faker as music
import io.github.serpro69.kfaker.sports.faker as sports
import io.github.serpro69.kfaker.tech.faker as tech
import io.github.serpro69.kfaker.travel.faker as travel
import io.github.serpro69.kfaker.tv.faker as tv
fun main() {
val f = faker {}
val books = books { }
val commerce = commerce { }
val creatures = creatures { }
val edu = edu { }
val games = games { }
val humor = humor { }
val japmedia = japmedia { }
val lorem = lorem { }
val misc = misc { }
val movies = movies { }
val music = music { }
val sports = sports { }
val tech = tech { }
val travel = travel { }
val tv = tv { }
repeat(100) {
println(f.name.name())
println(books.book.author())
println(commerce.commerce.vendor())
println(creatures.cat.name())
println(edu.job.field())
println(games.game.title())
println(humor.funnyName.name())
println(japmedia.naruto.eyes())
println(lorem.lorem.words())
println(misc.artist.names())
println(movies.movie.title())
println(music.music.albums())
println(sports.eSport.games())
println(tech.app.name())
println(travel.nation.language())
println(tv.archer.quotes())
}
}
Note
More details on the new Data Providers structure can be found in the docs