Beverage Buddy App Starter for Vaadin 14
This is a Vaadin 14 Vaadin-on-Kotlin example application, used to demonstrate features of the Vaadin Flow Java framework. A full-stack app: uses the H2 database instead of a dummy service.
The Starter demonstrates the core Vaadin Flow concepts:
- Building UIs in Kotlin with components
- Creating forms with
- Making reusable Components on server side with
- Creating Navigation with the Router API (
- Browserless testing: see the test suite package for the complete test implementation.
You can find the Online Beverage Buddy Demo running on Heroku.
The Vaadin 14 build requires node.js and npm. Vaadin Gradle plugin will install those for you automatically (handy for the CI); alternatively you can install those to your OS:
- Windows: node.js Download site - use the .msi 64-bit installer
sudo apt install npm
Also make sure that you have Java 8 (or higher) JDK installed.
To quickly start the app, just type this into your terminal:
git clone https://github.com/mvysny/beverage-buddy-vok cd beverage-buddy-vok ./gradlew appRun
Gradle will automatically download an embedded servlet container (Jetty) and will run your app in it. Your app will be running on http://localhost:8080.
Since the build system is a Gradle file written in Kotlin, we suggest you
use Intellij IDEA
to edit the project files. The Community edition is enough to run the server
./gradlew appRun. The Ultimate edition will allow you to run the
project in Tomcat - this is the recommended
option for a real development.
Runs in Vaadin 14 npm mode, using the Vaadin Gradle Plugin.
Both the development and production modes are supported. To prepare for development mode, just run:
./gradlew clean vaadinPrepareFrontend
To build in production mode, just run:
./gradlew clean build -Pvaadin.productionMode
If you don't have node installed in your CI environment, Gradle Vaadin plugin will download node.js for you automatically:
./gradlew clean build -Pvaadin.productionMode
To compile the entire project in production mode, run
To run the application in development mode, run
./gradlew appRun and open http://localhost:8080/.
To produce a deployable production-mode WAR:
- You will find the WAR file in
- To revert your environment back to development mode, just run
./gradlew vaadinPrepareFrontend(omit the
This will allow you to quickly start the example app and allow you to do some basic modifications.
Dissection of project files
Let's look at all files that this project is composed of, and what are the points where you'll add functionality:
|build.gradle.kts||Gradle build tool configuration files. Gradle is used to compile your app, download all dependency jars and build a war file|
|gradlew, gradlew.bat, gradle/||Gradle runtime files, so that you can build your app from command-line simply by running
|.travis.yml||Configuration file for Travis-CI which tells Travis how to build the app. Travis watches your repo; it automatically builds your app and runs all the tests after every commit.|
|Procfile||Tells Heroku hosting service how to run your app in a cloud. See below on how to deploy your app on Heroku for free.|
|.gitignore||Tells Git to ignore files that can be produced from your app's sources - be it files produced by Gradle, Intellij project files etc.|
|src/main/resources/||A bunch of static files not compiled by Kotlin in any way; see below for explanation.|
|simplelogger.properties||We're using Slf4j for logging and this is the configuration file for Slf4j|
|db/migration/||Database upgrade instructions for the Flyway framework. Database is upgraded on every server boot, to ensure it's always up-to-date. See the Migration Naming Guide for more details.|
|webapp/||contains static webapp resources, such as potential Polymer templates, components, the global app CSS file, etc. The CSS file references the Vaadin Lumo theme and configures it by the means of CSS variables. Polymer templates are not used in this project.|
|frontend/styles/shared-styles.html||The CSS styles applied to your web app. Vaadin by default uses Vaadin Lumo Theme; you can tweak the Lumo theme by the means of setting CSS variables.|
|src/main/kotlin/||The main Kotlin sources of your web app. You'll be mostly editing files located in this folder.|
|Bootstrap.kt||When Servlet Container (such as Tomcat) starts your app, it will run the
|MainLayout.kt||The main view of the app, it defines how the UI looks like and how the components are nested into one another. The UI is defined by the means of so-called DSL; see Karibu-DSL examples for more examples.|
|CategoriesList.kt||An example view which is constructed entirely server-side. Demonstrates the use of the Vaadin Grid component.|
|ReviewsList.kt||An example view which demoes the possibility of the
|ConfirmationDialog.kt||An example of a Yes-No dialog built entirely server-side.|
|AbstractEditorDialog.kt, CategoryEditorDialog.kt, ReviewEditorDialog.kt||Forms editing particular database entities, implemented as a dialogs.|
|Toolbar.kt||An example of a reusable component|
|backend/||Demonstrates the use of the VoK-ORM framework to represent database rows as objects|
|RestService.kt/||Demonstrates the possibility of having REST endpoints. See the class sources for details on how to access those endpoints.|
|DemoData.kt/||Pre-populates the database with some example data.|
|Category.kt/, Review.kt/||Two entities. Category simply lists a list of beverage categories such as 'Beer'. Review lists reviews made for a particular beverage; it references the beverage category as a foreign key into the Category table.|
For Vaadin 14 documentation for Java users, see Vaadin.com/docs.
For Vaadin-on-Kotlin documentation, head to Vaadin-on-Kotlin.
Development with Intellij IDEA Ultimate
The easiest way (and the recommended way) to develop VoK-based web applications is to use Intellij IDEA Ultimate. It includes support for launching your project in any servlet container (Tomcat is recommended) and allows you to debug the code, modify the code and hot-redeploy the code into the running Tomcat instance, without having to restart Tomcat.
- First, download Tomcat and register it into your Intellij IDEA properly: https://www.jetbrains.com/help/idea/2017.1/defining-application-servers-in-intellij-idea.html
- Then just open this project in Intellij, simply by selecting
File / Open...and click on the
build.gradlefile. When asked, select "Open as Project".
- You can then create a launch configuration which will launch the
explodedin Tomcat with Intellij: just scroll to the end of this tutorial: https://kotlinlang.org/docs/tutorials/httpservlets.html
- Start your newly created launch configuration in Debug mode. This way, you can modify the code
Ctrl+F9to hot-redeploy the code. This only redeploys java code though, to redeploy resources just press
Ctrl+F10and select "Update classes and resources"
Using Intellij IDEA Community
Intellij Community is free and can be used for the development as well. To launch your app in IDEA Community, just click the rightmost
Gradle tool button, then navigate to
beverage-buddy-vok / Tasks / gretty / appRun, right-click
appRun and select the first option "Run beverage-buddy-vok".