All Projects → simonschiller → Prefiller

simonschiller / Prefiller

Licence: apache-2.0
Prefiller is a Gradle plugin that generates pre-filled Room databases at compile time.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Prefiller

Ktargeter
Kotlin compiler plugin that allows overriding annotation use-site targets for properties
Stars: ✭ 24 (-44.19%)
Mutual labels:  gradle-plugin
Gradle Teamcity Plugin
Gradle plugin for developing TeamCity plugins
Stars: ✭ 30 (-30.23%)
Mutual labels:  gradle-plugin
Gradle Xjc Plugin
A Gradle plugin to run the XJC binding compiler during a build
Stars: ✭ 38 (-11.63%)
Mutual labels:  gradle-plugin
Gradle Defaults
Plugin providing opinionated defaults for Gradle projects.
Stars: ✭ 7 (-83.72%)
Mutual labels:  gradle-plugin
Soapui Gradle Plugin
SoapUI Gradle Plugin
Stars: ✭ 14 (-67.44%)
Mutual labels:  gradle-plugin
Easyandroid
一个完整基于kotlin的安卓开发框架,采用了mvvm设计模式。涵盖了: 1、基于retrofit2封装的通过kotlin协程实现的网络框架 2、基于阿里开源router修改的api-router实现项目模块化 3、基于glide的图片加载缓存框架 4、基于room实现的往来数据缓存加载 5、基于step实现的数据异步提交 6、基于PreferenceHolder实现的本地数据快速存储 7、基于mlist实现的简单复杂列表的快速开发扩展 8、定制的toolbar可以自适应异形屏,挖孔屏,水滴屏等等。。 本框架几乎涵盖了开发所需的所有模块组件。简单fork之后就可以基于框架快速开发。
Stars: ✭ 33 (-23.26%)
Mutual labels:  room
Myweatherkotlinflow
Android app that shows weather at your current location or any custom location you specify. Uses Kotlin Flow for data streaming and coroutines for asynchronous work. Also leverages Room, navigation component, Viewmodel and Livedata Jetpack components with MVVM presentation layer architecture. Dagger 2 with Dagger android for dependency injection
Stars: ✭ 23 (-46.51%)
Mutual labels:  room
Posts Mvvm Daggerhilt Dynamic Feature Rxjava3 Flow Sample
Posts Api sample with Kotlin RxJava3/Coroutines Flow, Clean Architecture, Offline first/last with Room + Retrofit2, Dagger Hilt, Dynamic Feature Modules, Static Code Analysis, Gradle DSL, MockK+ MockWebServer with Test Driven Development including Api and Database tests
Stars: ✭ 41 (-4.65%)
Mutual labels:  room
Androidarchitecture
Recommended architecture by Android
Stars: ✭ 883 (+1953.49%)
Mutual labels:  room
Social Note
Social Note - Note-taking, sharing, time & location reminder
Stars: ✭ 38 (-11.63%)
Mutual labels:  room
Pokemongo
神奇宝贝 (PokemonGo) 基于 Jetpack + MVVM + Repository 设计模式 + Data Mapper + Kotlin Flow 的实战项目,如果这个仓库对你有帮助,请仓库右上角帮我 star 一下,非常感谢。
Stars: ✭ 848 (+1872.09%)
Mutual labels:  room
Gradle Kotlin Aspectj Weaver
A Gradle plugin that allows you to weave your compiled Java and Kotlin files with AspectJ
Stars: ✭ 14 (-67.44%)
Mutual labels:  gradle-plugin
Androidroom
Android example to show how to use Room to access SQLite database on device for reading and writing data. This example also shows how to use LiveData and ViewModel with Room to build reactive, well performing and easy to maintain applications.
Stars: ✭ 36 (-16.28%)
Mutual labels:  room
Plantuml Gradle Plugin
Gradle plugin to build PlantUML diagrams from code (for living and up-to-date documentation)
Stars: ✭ 27 (-37.21%)
Mutual labels:  gradle-plugin
Gradle Docker Plugin
Gradle plugin for managing Docker images and containers.
Stars: ✭ 994 (+2211.63%)
Mutual labels:  gradle-plugin
Android Architecture Components Kotlin
Clean code App with Kotlin and Android Architecture Components
Stars: ✭ 23 (-46.51%)
Mutual labels:  room
Codeanalysis
Android静态代码分析
Stars: ✭ 31 (-27.91%)
Mutual labels:  gradle-plugin
Android Debug Database
A library for debugging android databases and shared preferences - Make Debugging Great Again
Stars: ✭ 7,946 (+18379.07%)
Mutual labels:  room
Hunter
A fast, incremental, concurrent framework to develop compile plugin for android project to manipulate bytecode
Stars: ✭ 999 (+2223.26%)
Mutual labels:  gradle-plugin
Android Clean Architecture Example
Yet another Android clean architecture example using RxJava and Room.
Stars: ✭ 37 (-13.95%)
Mutual labels:  room

Build Status GitHub Release License

Prefiller

Prefiller is a Gradle plugin that generates pre-filled Room databases at compile time.

Motivation

With version 2.2, the Room persistence library added support for pre-populated databases. This works by including a pre-filled database in the assets directory. Generating this database can be tedious and error-prone and has to be repeated whenever the underlying schema changes.

Prefiller offers a convenient way to generate pre-filled databases at compile time. You simply provide a script file that populates your database, Prefiller takes care of the rest. It will generate a database matching the latest schema, execute your script on this database and include the database in the assets. This way, changing the schema or adding additional pre-filled data is much easier. Additionally, the changes to the pre-filled database are now present in script form, making changes easier to review in pull requests.

Usage

To start using Prefiller, you just have to follow these steps.

Add Prefiller to your project

First you need to add the Prefiller plugin to your project by adding this block of code to your build.gradle.

plugins {
    id "io.github.simonschiller.prefiller" version "1.0.0"
}

Alternatively, you can also use the legacy plugin API. Simply add the following snippet to your top-level build.gradle.

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "io.github.simonschiller:prefiller:1.0.0"
    }
}

When you're using the legacy plugin API, you also have to apply the plugin in the build.gradle of your module.

apply plugin: "io.github.simonschiller.prefiller"

You can also find instructions on how to use the Prefiller plugin on the Gradle plugin portal.

Write your setup script

Next you need to create a .sql script with all your setup statements. Simply place this file somewhere in your project. Prefiller will use this file to populate the database, so make sure the statements are valid and match the database schema.

-- src/main/sql/setup.sql

INSERT INTO people(firstname, lastname, age) VALUES ("Mikael", "Burke", 38);
INSERT INTO people(firstname, lastname, age) VALUES ("Ayana", "Clarke", 12);
INSERT INTO people(firstname, lastname, age) VALUES ("Malachy", "Wall", 24);

Configure the Prefiller plugin

Lastly, you have to configure the Prefiller plugin in your build.gradle by linking the database class with the script file you just created.

prefiller {
    database("people") {
        classname.set("com.example.PeopleDatabase")
        script.set(layout.projectDirectory.file("src/main/sql/setup.sql"))
    }
}

Using the pre-filled database in code

Now you're ready to go. Simply use the generated database file when you build your Room database.

val database = Room.databaseBuilder(context, com.example.PeopleDatabase::class.java, "people.db")
    .createFromAsset("people.db") // File name is configured in the plugin
    .build()

How it works

Room can be set up to generate a schema definition file, this file contains all information needed to construct a matching database. Prefiller simply parses this file, generates the database accordingly and runs the provided script file. To make this work, you have to make sure that Room is configured to generate schema files.

android {
    defaultConfig {
        // Java
        javaCompileOptions {
            annotationProcessorOptions {
                arguments["room.schemaLocation"] = "$projectDir/schemas".toString()
            }
        }

        // Kotlin
        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas")
            }
        }
    }
}

You can find more information on how to do this in the official Room documentation.

Working with this project

The source code of the plugin is located in the prefiller folder. The sample folder contains several sample projects that show how the plugin is used. The tests of these sample projects also function as E2E tests for the Prefiller plugin.

  • Build the plugin: ./gradlew :prefiller:assemble
  • Run unit tests: ./gradlew :prefiller:test
    • By default, all tests will be executed against all compatible Gradle and Android Gradle plugin versions. If you want to run tests against a specific version, you can use the -PagpVersion and -PgradleVersion flags.
  • Run all tests:
    • First publish the plugin to your local Maven repo: ./gradlew :prefiller:publishToMavenLocal
    • Then execute the tests: ./gradlew test

License

Copyright 2020 Simon Schiller

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].