Gradle

Aus Peter Fuerholz' Wiki
Zur Navigation springen Zur Suche springen

Installation

Tool Installation

  1. Download from Gradle HP
  2. Unzip with e.g. Archive Manager
  3. mv ./gradle-1.9 /usr/share
  4. sudo chown -R root:root gradle-1.9
  5. sudo gedit /etc/environment
    1. Add export GRADLE_HOME=/usr/share/gradle-1.9
    2. Append :/usr/share/gradle-1.9/bin to PATH variable
    3. Save and restart computer
  6. Call gradle -v and check version

Eclipse Tooling

(( Unable to do today...

Install Spring DashBoard

(Maybe this is not really necessary. Reason for that was, that installing Gradle wanted to install Spring Dashboard which was not possible.)

  1. Download http://dist.springsource.com/release/TOOLS/composite/e3.6/bookmarks.xml
  2. Eclipse, Preferences, Install/Updates, Available Update Sites, Import..., select downloaded 'bookmarks.xml'
(File is placed in Documents/Sw-Dev/Gradle folder)
  1. Eclpse, Help, Install, 'SpringSource Update Site for Eclipse 3.6...', select:
    • Core Spring IDE
    • Core / STS
    • Extensions / Spring IDE

))

Install Gradle

See Gradle HP Installing Gradle Tooling from update site

Alternatively you can install from update sites. The following update sites are available:

  1. Open Help >> Install New Software
  2. Paste a Gradle update site link into the "Work with" text box.
  3. Ensure that the option "Group Items by Category" is enabled.
  4. Select the top-level node 'Extensions / Gradle Integration'. Click "Next".
  5. Review the list of software that will be installed. Click "Next" again.
  6. Review and accept licence agreements and Click "Finish".

If you follow this installation procedure in a plain Eclipse, this will install the STS Dashboard. This gives you an easy way to subsequently install Groovy Eclipse as well. In my case I was unable to install the STS Dashboard though...

Install Groovy

  1. Help, Install, Add: http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e4.2/
  2. Install almost all provided from there (see [1])

For this to work I had to rename the files 'notice.html' and 'epl-v10.html' in directory /opt/eclipse4-3-1. (This is rather odd but I don't know...) Installing Groovy for Gradle is higly adviced. Otherwise you have no highlighting in the editor etc.

Simple Gradle Build Script

Here is a simple build script for building a java library (jar):

 apply plugin: 'java'
 sourceCompatibility = 1.5
 version = '1.0'
 
 sourceSets {
   main {
     java {
       // Overwrite default value of 'src/main/java':
       srcDirs = ['src']
       // Only compile following 2 classes:
       include 'se/datadosen/util/SmartResourceBundle.java', 'se/datadosen/util/IO.java'
     }
   }
 }
 
 jar {
   manifest {
     attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
   }
 }

Rules:

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

is equivalent to:

 sourceSets.main.srcDirs = ['src']

Usage with Eclipse

See New Gradle Project Wizard. Creating an Eclipse project:

  • File, New, Project..., Gradle, Gradle Project, Next etc.

The usage is then very easy:

  • Right mouse-click on Gradle project, 'Gradle', 'Refresh dependencies'
  • Under the project next to JRE System Library a "folder" named 'Gradle Dependencies' should appear where all referenced libraries should be enlisted.

See:

Gradle, Vaadin & Eclipse

There exist following plugins:

  • Eclipse plugin for Vaadin
This plugin enables to compile the Widgetset, theme-file (*.scss), easily create web-projects to be run on Tomcat, create sample applications, widgets etc.
  • Eclipse plugin for Gradle (Spring Gradle integration plugin)
Enables to run the build.gradle files.

Nevertheless this does NOT mean that working with all 3 of them together is a piece of cake! See following thread to go further into that: Issue 84

The Gradle plugin is able to:

  • create Jars, Wars and run Jetty
  • create Eclipse project files. The created project files are not typed as Spring Gradle projects (not having a 'G' in its icon.).

As you can see under Issue 84 web applications (and Vaadin Addons) must be created like follows:

  • create a Gradle project (mkdir <projectfile>, cd <projectfile>, gedit build.gradle, gradle eclipse, gradle createVaadinProject)
  • Import in Eclipse as Gradle project, build it and make sure that the Dependency Manager is not engaged.
  • Use Gradle script via right-mouse-click, Gradle, Refresh All.
  • Build project via 'Run As', 'Gradle Build...', 'build'
  • Run on Tomcat 7 (Jetty may not work since too old version is used: ASM library is version 3.1.1, Parboiled needs 4.1)

Do mind:

  • If you have to implement widgets with specific client code:
    • Implement them as separate Gradle-Eclipse- or Vaadin-Eclipse-projects and deploy them to a local Ivy repository. (Easiest would be possibly as Vaadin-Eclipse-project.)
    • Use Gradle-Eclipse projects for your main business part and create a Gradle-Eclipse-project for the Web-application.

Some links:

  • Using Vaadin Add Ons Do mind that the automatic widget compilation does not occur on Vaadin-Eclipse projects. Compilation occurs also when using the Gradle plugin for Vaadin but there you have to build it on the command-line. E.g.:
 gradle clean
 gradle build
 gradle vaadinRun


Gradle plugin for Vaadin

Things to acknowledge when using this plugin:

  • If you change your *.gwt.xml by hand (e.g. adding a css file) it gets overwritten by the gradle build (gradle build). See issue.
See this page about ways how to integrate CSS in your Add on. I my case I placed the StyleSheet-tag on the component class not the connector class as suggested in the tag documentation. (-> Don't use on client part.) The CSS file is placed next to the Java code.
  • Specific to my case: There is an old Jetty-version used which references ASM library in version 3.1, but Parboiled library needs ASM in version 4.1!

Create an Eclipse Project by means of the Gradle Plugin for Vaadin

 mkdir <project name>
 cd <project name>
 gedit build.gradle

Then enter:

   task wrapper(type: Wrapper) {
     gradleVersion = '1.9'
   }
   apply from: 'http://plugins.jasoft.fi/vaadin.plugin'
   
   apply plugin: 'java'
   apply plugin: 'eclipse-wtp'  // superset to 'eclipse'
   
   vaadin {
     version = '7.1.8'
     widgetset = '<package name>.<project name>'
   }
   
   dependencies {
     // enter your dependencies
   }

Save and exit, then:

 gradle wrapper  // creates gradlew, the gradle wrapper
 gradlew createVaadinProject

If you want to create a widget:

 gradlew createVaadinComponent  // starts internal web server (Jetty)
 gradlew eclipse
 [gradlew eclipseWtp  // seems not necessary]

With apply plugin: 'eclipse-wtp' a Web project is created. Open Eclipse and import the project as Gradle project. Unset 'Dependency Manager' and 'Build Model', unset 'Dependency Manager' again and press OK.

For building the project:

  • right mouse click on project, 'Run as', 'Gradle Build...', select 'build', 'Run'
  • Run task 'vaadinRun' (if not conflicting with Parboiled library)
  • Otherwise: Right mouse click, Run on server, Tomcat 7 etc.

On Vaadin AddOn-project you have run task 'uploadArchives' as well. (Copies artifacts to ~/gradleRepository)

Update Vaadin

You have to update your Vaadin version go on like this (within Eclipse):

  1. Go through all your build.gradle files and update the version:
    vaadin {
    version = '7.1.9'
    ...
  2. Then right click on your projects and select 'Gradle', 'Refresh all'. Rebuild the projects by 'Run as', 'Gradle build'.
  3. Refresh server: Go to server view, right-click on server, 'Clean...'
  4. Check that old version is has been extincted for this server:
    • Go through all projects and check library folders ('JRE System Library', 'Web App Libraries', 'Referenced Libraries').
    • Run your application with debug window: Attach ?debug to your application URL. On the debug screen select 'i' and check versions (line should appear in red):
    Client engine version 7.1.9
    Server engine version 7.1.8
    • Alternatively you can check following directory for outdated libraries: /home/pfu/workspace4.3.1gradle/.metadata/.plugins/org.eclipse.wst.server.core/tmp&lthighest nb>/wtpwebapps/cellendraMain/WEB-INF/lib (This path can be looked up in Eclipse when you double click on your Tomcat server: 'Overview', 'Server locations', 'Server path'.) Don't try to delete libs here, they get created again...
    If you have old libraries you most probably missed to update one of the referenced projects.

Gradle Tips and Hints

  • Look up the Maven Repository
  • Adding/Removing code-/sourcesets
  • Very useful commands:
    • gradle tasks  : shows all available tasks (gradle -q tasks --all for all, -q for quiet)
    • gradle dependencies  : shows dependencies on other library / projects
    • gradle projects  : shows subprojects
    • gradle properties  : shows properties
  • Gradle tasks can be abbreviated (as long they stay unique): gradle gT instead of gradle groupTherapy
  • An ivy repository can be in its simplest form just a local folder. If you upload an artifact by means of updateArchives gradle creates the necessary file structure for you.
  • Don't mix flatDirs- and ivy-repositories. If you upload to a flatDirs-repository you have to reference it as this when to download.
  • Make sure that all Eclipse projects are in faceted form: Alt-Enter on project, select 'Project Facets'. (I had a project not deployed to Tomcat since it wasn't in that form. After the conversion and refreshs (F5) it worked...)