Set up a new vaadin project.

Presumptions.

  1. IntelliJ community edition installed. (Version 14.1.4)

Steps

  1. Setup gradle environment in windows.
    Setting up gradle under windows isn't trivial. Via this trick we use IntellIJ features, so we don't have to do it ourselves.

  2. In IntelliJ: Create new project

    1. Gradle project.
    2. GroupId: com.example
    3. ArtifactId: myvaadinembedded
    4. Tick: "Use default gradle wrapper (recommended)"
    5. Setup location of project to your liking.
    6. Select .ipr File based (Essential for working with vaadin-gradle-plugin)
    7. Hit finish.
  3. Setup build.gradle

     apply plugin: 'java'
     apply plugin: 'idea'
     apply from: 'http://plugins.jasoft.fi/vaadin.plugin'
     
     sourceCompatibility = 1.8
     version = '1.0'
     
     repositories {
     mavenCentral()
     }
     
     dependencies {
     testCompile group: 'junit', name: 'junit', version: '4.11'
     
     compile 'org.apache.tomcat:tomcat-catalina:7.0.41'
     compile 'org.apache.tomcat:tomcat-util:7.0.41'
     compile 'org.apache.tomcat.embed:tomcat-embed-core:7.0.41'
     }
     
     // Unclear why this is required, but intellij refuses to copy resources unless included.
     task copyResources(type: Copy) {
     from "${projectDir}/src/main/webapp"
     into "${buildDir}/classes/main"
     }
     processResources.dependsOn copyResources
    1. Refresh gradle from intellij, so it imports the extra tasks.
    2. Execute the vaadinCreateProject task, so it creates a basic runnable vaadin UI.
    3. Execute the idea task, to re-create the project .ipr file. (Fixes dependencies)
      Warning: This needs to be done every time you change the build.gradle file...
    4. Execute the vaadinCompileThemes task.
    5. Execute the vaadinCompileWidgetset task.
  4. Create Main.java embedded launcher.

     package com.example.myapplication;
     
     import org.apache.catalina.Context;
     import org.apache.catalina.LifecycleException;
     import org.apache.catalina.Wrapper;
     import org.apache.catalina.startup.Tomcat;
     
     import java.io.File;
     import java.io.IOException;
     
     public class Main {
       public static void main(final String[] args) throws IOException, LifecycleException {
         Tomcat tomcat = new Tomcat();
         tomcat.setPort(8080);
     
         File base = new File(System.getProperty("java.io.tmpdir"));
         Context rootCtx = tomcat.addContext("/app", base.getAbsolutePath());
         Wrapper wrapper = Tomcat.addServlet(rootCtx, "myApp", new MyApplicationServlet());
         wrapper.addInitParameter("ui", "com.example.myapplication.MyApplicationUI");
     
         rootCtx.addServletMapping("/*", "myApp");
     
         tomcat.start();
         tomcat.getServer().await();
       }
     }
  1. You'll probably need to run the idea task once more. And everytime your dependencies break.