Archive: December 2014

Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

Posted on by  
Hubert Klein Ikkink

Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have to add this single line and reference our existing Ant build XML file and all Ant tasks can now be executed as Gradle tasks. We can automatically rename the Ant tasks if we want to avoid task name collisions with Gradle task names. We use a closure argument with the importBuild method and return the new task names. The existing Ant task name is the first argument of the closure.

Let's first create a simple Ant build.xml file:

Continue reading →

Java 8 StringJoiner

Posted on by  
Sjoerd Schunselaar

At the release of Java 8 the most attention went to the Lamda’s, the new Date API and the Nashorn Javascript engine. In the shade of these, there are smaller but also interesting changes. Amongst them is the introduction of a StringJoiner. The StringJoiner is a utility to delimit a list of characters or strings. You may recognize the code below:

String getString(List<String> items)
    StringBuilder sb = new StringBuilder();
    for(String item : items) {
        if(sb.length != 0) {
            sb.append(",");
        }
        sb.append(item);
    }
    return sb.toString();
}

Continue reading →

Awesome Asciidoctor: Nested Delimited Blocks

Posted on by  
Hubert Klein Ikkink

In our Asciidoc markup we can include delimited blocks, like sidebars, examples, listings and admonitions. A delimited block is indicated by a balanced pair of delimiter characters. For example a sidebar starts and ends with four asterisk characters (****). If we want to nest another delimited block of the same type we must add an extra delimiter character at the start and end of the nested block. So when we want to nest another sidebar block inside an existing sidebar block we must use five asterisk characters (*****).

In the following example Asciidoc source we have several blocks with nested blocks:

Continue reading →

Groovy @CompileStatic vs. Grails new @GrailsCompileStatic

Posted on by  
Albert van Veen

Grails is built on Groovy which is known as a dynamic language. The dynamic nature of Groovy offers a lot of powerful features but also defers the detection of errors from compile time to runtime. To shorten the feedback cycle for your code Groovy has a handy annotation which will make sure that your classes is are statically compiled. This will give you fast feedback for a lot of mistakes and you also will benefit from the increased performance offered by the static complication. Unfortunately in Grails this annotation prevents you from using the very useful dynamic GORM methods like list(), get() and the dynamic finder methods. Groovy does not recognize these Grails methods during compile time; see the example below.

@CompileStatic
class BookController(){

     def save(){
       //This will successfully compile
    }

    def get(){
       Book.findByName(params.name)
       //this will throw a compile error since the findByName method is not known
       //at compile time
    }

    @CompileStatic(TypeCheckingMode.SKIP)
    def delete(){
       //by setting the TypeCheckinMode, this method will be skipped
    }
}

Continue reading →

Gradle Goodness: Continue Build Even with Failed Tasks

Posted on by  
Hubert Klein Ikkink

If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have fast feedback of our build status. If we don't want to this and want Gradle to execute all tasks, even though some might have failed, we use the command line option --continue. When we use the --continue command line option Gradle will execute every task where the dependent tasks are not failing. This is also useful in a multi-module project where we might want to build all projects even though some may have failing tests, so we get a complete overview of failed tests for all modules.

In the following Gradle build file we have two tasks. The task failTask throws a TaskExecutionException to purposely fail the task. The successTask will not fail:

Continue reading →

Gradle Goodness: Skip Building Project Dependencies

Posted on by  
Hubert Klein Ikkink

If we use Gradle in a multi-module project we can define project dependencies between modules. Gradle uses the information from the project dependencies to determine which tasks need to be run. For example if module B depends on module A and we want to build module B, Gradle will also build module A for us, because module B depends on it. But if we know for sure that module A is up to date and has not changed, we can also instruct Gradle to skip building module A, when we build module B.

Let's start with the following module structure, where each module depends on the module above it. So module services depends on common and module web depends on services:

Continue reading →

Awesome Asciidoctor: Span Cell over Rows and Columns

Posted on by  
Hubert Klein Ikkink

When we define a table in Asciidoctor we might want to span a cell over multiple columns or rows, instead of just a single column or row. We can do this using a cell specifier with the following format: column-span.row-span+. The values for column-span and row-span define the number of columns and rows the cell must span. We put the cell specifier before the pipe symbol (|) in our table definition.

In the following example Asciidoctor markup we have three tables. In the first table we span a cell over 2 columns, the second table spans a cell over 2 rows and in the final table we span a cell over both 2 columns and rows.

Continue reading →

Grails Goodness: Create New Application without Wrapper

Posted on by  
Hubert Klein Ikkink

Since the latest Grails versions a Grails wrapper is automatically created when we execute the create-app command. If we don't want the wrapper to be created we can use the command argument --skip-wrapper. If later we changed our mind and want the Grails wrapper we can simply run the wrapper command from our Grails application directory.

Let's run the create-app command with the --skip-wrapper argument. If we check the contents of the created directory we see that the wrapper files are not created:

Continue reading →

shadow-left