Version 2, last updated by jeppenejsum at May 05, 2011 12:56 UTC

This article is a copy of the blog post written by Jeppe Nejsum Madsen on his blog

Creating a project is as simple as cloning a project from Git:

$ git clone git@github.com:jeppenejsum/liftstart.git

This will fetch all the files from github. The project just created is a basic Lift application with database support (using H2) and simple user registration. The files follow a standard directory scheme.

Gradle reads the build.gradle file to determine the tasks that are available in the project. The build.gradle in this project is fairly simple, mostly adding the scala-tools.org repository and specifying the dependencies needed to compile and test the project.

// Minimal build.gradle for Lift project
apply {
  plugin 'scala'
  plugin 'war'
  plugin 'jetty'
}

scalaVersion = '2.7.7'
liftVersion = '2.0-M4'

jettyRun.contextPath = "/"

repositories {
  mavenCentral()
  mavenRepo name:'scala-releases', urls:'http://scala-tools.org/repo-releases/'
}

dependencies {
  scalaTools "org.scala-lang:scala-compiler:$scalaVersion",
    "org.scala-lang:scala-library:$scalaVersion"

  compile "org.scala-lang:scala-library:$scalaVersion",
    "net.liftweb:lift-webkit:$liftVersion",
    "net.liftweb:lift-mapper:$liftVersion",
    "net.liftweb:lift-json:$liftVersion",
    "net.liftweb:lift-util:$liftVersion",
    "net.liftweb:lift-common:$liftVersion",
    "com.h2database:h2:1.1.117"

  testCompile "junit:junit:4.5",
    "org.scala-tools.testing:specs:1.6.1",
    "org.scala-lang:scala-compiler:$scalaVersion",
    'org.mortbay.jetty:jetty:6.1.22',
    'org.mortbay.jetty:jetty-util:6.1.22',
    'org.mortbay.jetty:jetty-management:6.1.22'

  providedCompile 'javax.servlet:servlet-api:2.5'
}

task wrapper(type: Wrapper) {
  gradleVersion = '0.9-preview-1'
}

In order to run a task you use the syntax

$ ./gradlew taskName

This will install gradle if it’s not already installed and then execute the specified task in the build script. So to compile the project and load it within the built-in Jetty web server, use the following command:

$ ./gradlew jettyRun

Running this (and ignore the warnings about multiple SLF4J bindings, this is a bug in the built-in jettyRun task) and then browsing to http://localhost:8080 should show something like this:

To package the project such that it can be moved to a standalone web server, you can create a war file by executing

$ ./gradlew war

This will create the file build/libs/liftstart.war which can be copied to the apps directory of any servlet container.