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

  • 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

主站蜘蛛池模板: 大荔县| 潼关县| 镇远县| 黄冈市| 嘉定区| 郴州市| 海林市| 辽源市| 灵川县| 靖州| 阿瓦提县| 营口市| 义马市| 勃利县| 泰安市| 武鸣县| 滁州市| 常德市| 金溪县| 五家渠市| 溆浦县| 龙里县| 山阳县| 金溪县| 临颍县| 鲜城| 靖宇县| 修文县| 托克逊县| 静安区| 乳山市| 炉霍县| 东丽区| 自治县| 额尔古纳市| 莒南县| 岑溪市| 兴隆县| 无棣县| 于都县| 沙河市|