Suresh Payankannur

Showing posts with label build. Show all posts
Showing posts with label build. Show all posts

Friday, September 5, 2014

Gradle and Embedded Jetty access log

The standard Jetty plugin for Gradle has limited features. For example, there seems to have no option to configure access logs with this plugin. Luckily there is a much more feature rich jetty plugin called JettyEclipse for Gradle. This can be found here. Configuring this plugin is quite easy. Add the following into your build.graddle.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath (group: 'com.sahlbach.gradle', name: 'gradle-jetty-eclipse-plugin', version: '1.9.+')
    }
}
apply plugin: 'jettyEclipse'

jettyEclipse {
    System.setProperty("catalina.home", "${project.buildDir}")   
    requestLog = new File("${project.buildDir}/logs/access.log")
}

Then run gradle clean jettyEclipseRun

Handling Resources with Gradle

Gradle copies resources to a different directory than Maven. So when migrating from Maven, the source code needs to be changed to take care of the new resource locations. In order to keep the resources are copied to the correct location, add the following into your projects build.gradle file.

project.buildDir = 'target'

sourceSets {
    main {
        output.resourcesDir "${project.buildDir}/classes"
    }
    test {
        output.resourcesDir "${project.buildDir}/classes/test"
    }
}

Querydsl JPA Model Generation with Gradle

Querydsl is a very useful tool to write concise JPA queries. This requires a plugin to generate the meta model classes that will be referenced in the queries. There is a maven plugin to handle the code generation. But when using Gradle, this needs to be configured manually. Add this to the build.gradle file.
ext {
    generatedSourcesDir = file("${buildDir}/generated-sources")
    querydslVersion    = "3.4.2"
}
sourceSets {
    main {
        java {
            srcDir "src/main/java"
            srcDir generatedSourcesDir
        }
    }
}
configurations {
    querydslapt
}
task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
    source = sourceSets.main.java
    classpath = configurations.compile + configurations.querydslapt
    options.compilerArgs = [
            "-proc:only",
            "-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
    ]
    destinationDir = generatedSourcesDir
}
compileJava {
    doFirst {
        generatedSourcesDir.mkdirs();
    }
    options.compilerArgs += ['-s', generatedSourcesDir]

    dependsOn generateQueryDSL
}
dependencies {
      compile  "com.mysema.querydsl:querydsl-core:${querydslVersion}"
      compile  "com.mysema.querydsl:querydsl-jpa:${querydslVersion}"
      querydslapt  "com.mysema.querydsl:querydsl-apt:${querydslVersion}"
}

Blog Archive

Scroll To Top