官术网_书友最值得收藏!

  • Vaadin 7 Cookbook
  • Jaroslav Holaň Ond?ej Kvasnovsk?
  • 390字
  • 2021-07-23 14:19:32

Building a Vaadin application with Gradle

Gradle is the next generation of builds tools. It helps with building, publishing, deploying, and actually any other task which should be automated.

Gradle build scripts are written in Groovy, which makes this build tool really straightforward and easy to use. In this recipe, we are going to use the Groovy language.

We will use the Gradle plugin for Vaadin, which makes the development of Vaadin applications in Groovy really luxurious.

Getting ready

Let's install Gradle before we start from http://gradle.org/installation.

Create a new directory where we will place the new project:

mkdir vaadin-in-gradle

How to do it...

Carry out the following steps in order to create a new project in Gradle:

  1. Create a file build.gradle in the project root. It is going to be just one line that is necessary for running the project.
    apply from: 'http://plugins.jasoft.fi/vaadin.plugin'
    
  2. Run the createVaadinProject target and fill in the name of the application and package. Alternatively, just press the Enter key twice and let the plugin create the default application inside the default package.
    gradle createVaadinProject
    
  3. Run target vaadinRun, which starts up the embedded Jetty web server, and the application will be deployed.
    gradle vaadinRun
    

    The URL of the web server is printed out in the console as follows:

    :themes
    :compileJava
    :processResources UP-TO-DATE
    :classes
    :widgetset
    :vaadinRun
    Application running on http://0.0.0.0:8080 (debugger on 8000)
    > Building > :vaadinRun
    

How it works...

Gradle is following the convention over configuration paradigm and that is why Gradle build scripts are so minimalistic. For example, the default source folder for Groovy files is src/main/groovy and we can change it by the following code that we place inside the build script build.gradle.

sourceSets {
  main {
    groovy {
      srcDirs = ['src/groovy']
    }
  }
}

The next valuable thing about Gradle is good documentation:

http://www.gradle.org/docs/current/userguide/userguide_single.html

Let's have a bit more detailed look at what the Gradle plugin for Vaadin did for us.

When we run the createVaadinProject target, the plugin creates two files. MyApplication.groovy inside com.example.myapplication package and web.xml in src/main/webapp/WEB-INF folder.

The plugin also defines the vaadinRun target that starts up the Jetty web server and deploys the application.

There's more...

There are other targets such as createVaadinTheme, devmode, widgetset, and more in the Vaadin plugin. All these, and more information about the plugin configuration, can be found on the GitHub page:

https://github.com/johndevs/gradle-vaadin-plugin

主站蜘蛛池模板: 乌拉特前旗| 巴里| 岳池县| 葫芦岛市| 拜城县| 龙川县| 辛集市| 四会市| 彰武县| 宜州市| 乌鲁木齐县| 忻城县| 类乌齐县| 沭阳县| 樟树市| 桂东县| 临汾市| 清丰县| 华阴市| 高清| 庐江县| 萍乡市| 托里县| 黑龙江省| 罗平县| 玛纳斯县| 孙吴县| 政和县| 东乡县| 会同县| 砀山县| 大宁县| 泾阳县| 桐乡市| 交城县| 汉寿县| 颍上县| 桐柏县| 临夏市| 北海市| 汝州市|