To define system properties for our Gradle build we can use the command line option --system-prop
or -D
. But we can also add the values for system properties in the gradle.properties
file of our project. This file contains project properties we want to externalized, but if we prefix the property name with systemProp.
the property is turned into a system property. For a multi-module build only system properties defined in the gradle.properties
file in the root of the project structure are used, others are ignored.
In the following build script we have the task showSystemProperty
. Inside the task we assert the value of the system property sample
and the project property sample
:
Continue reading →
One of the great features of Asciidoctor is the support for extensions. If we want to have some special feature we want to use, but is not supported by Asciidoctor, we can add our own extension. On the Java platform we can write those extensions in for example Java and Groovy. When we use Gradle as the build tool with the Asciidoctor plugin we can write the code for the extension in our Gradle build file with the Groovy extension DSL.
Suppose we want to write a new inline macro that will transform the following markup issue:PRJ-100[]
into a link that points to the web page for issue PRJ-100. First we create our Asciidoctor source document:
Continue reading →
When you start using Scala, it's tempting to also start using sbt. You can also use your favorite build tool: Gradle. This is my default Gradle build file:
apply plugin: 'scala'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.5'
compile group: 'com.typesafe.akka', name: 'akka-actor_2.11', version: '2.3.9'
compile group: 'com.typesafe.akka', name: 'akka-remote_2.11', version: '2.3.9'
testCompile group: 'org.scalatest', name: 'scalatest_2.11', version: '2.2.4'
}
//run the akka application
task run(type: JavaExec, dependsOn: classes) {
//object to run. (The one that extends App)
main = 'pi.Pi'
classpath sourceSets.main.runtimeClasspath
classpath configurations.runtime
}
//run scala tests. These are not automatically picked up by gradle,
//so we run them like this.
task spec(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/test', '-o']
classpath = sourceSets.test.runtimeClasspath
}
Continue reading →
Creating a list with Asciidoctor markup is easy. To create an unordered we need to start a line with an asterisk (*
) or hypen (-
). We can add some extra markup to create a checked list. If we add two square brackets ([]
) to the list item we have a checklist. To have an unchecked item we use a space, for a checked item we can use a lowercase x (x
) or an asterisk (*
).
In the next example we define a shopping cart list with Asciidoctor markup:
Continue reading →
With Asciidoctor we can create numbered lists easily. When we want to change the number the list starts with we use the start
attribute when we define the list.
== Numbered List
.Default
. Makes writing easy
.. Keep focus
.. Syntax
. Different output formats
// Start this list from 10.
[start=10]
.Start from 10
. Makes writing easy
// We can use it on all levels.
[start=10]
.. Keep focus
.. Syntax
. Different output formats
Continue reading →
Document attributes are like variables for your Asciidoctor document. Normally when we reference an attribute that is not set in our Asciidoctor markup the reference is still in the output. This is very handy, because we immediately see that a document attribute is not set. But we can customize this behavior with the document attribute attribute-missing
. We can use the default value skip
, which leaves the reference in the output. Another option is drop
, which means the reference is dropped from the output. Finally we can set the value to drop-line
, where the complete line with the attribute reference is dropped from the output.
In the following sample Asciidoctor markup we set the three values for the attribute attribute-missing
:
Continue reading →
Recently I had to access the XML-RPC WordPress API for a small project. Luckily with Groovy we can access a XML-RPC server in a Groovy way. We need to use the Groovy XML-RPC module, which is a separate dependency. The module provides code to write a XML-RPC server, but also code to access a XML-RPC server as client. We use the class XMLRPCServerProxy
in the package groovy.net.xmlrpc
to act as a client to a XML-RPC API. The XMLRPCServerProxy
class only needs to know the URL to access the API. All API methods are dynamically dispatched to the server, so it is very flexible.
In the following Groovy script we use the WordPress XML-RPC API to access posts:
Continue reading →
NOTE: ngImprovedTesting is AngularJS library to make mock testing AngularJS code more easy.
For more information about ngImprovedTesting be sure to read its (updated) introductory blog post.
Just released version 0.3 ngImprovedTesting with a much improved ModuleBuilder. Prior to 0.3 usage of ngImprovedTesting might be troublesome due to fact that the ModuleBuilder:
Continue reading →
Spock supports JUnit rules out of the box. We simply add a rule with the @Rule
annotation to our Spock specification and the rule can be used just like in a JUnit test. The Spring Boot project contains a JUnit rule OutputCapture
to capture the output of System.out
and System.err
.
In the following example specification we apply the OutputCapture
rule and use it in two feature methods:
Continue reading →
Since Groovy 2.4 we can use the indices
property on a Collection
to get the indices of the elements in the collection. We get an IntRange
object as a result.
def list = [3, 20, 10, 2, 1]
assert list.indices == 0..4
// Combine letters in alphabet
// with position (zero-based).
def alphabet = 'a'..'z'
def alphabetIndices = [alphabet, alphabet.indices].transpose()
// alphabetIndices = [['a', 0], ['b', 1], ...]
// Find position of each letter
// from 'groovy' in alphabet.
def positionInAlphabet = 'groovy'.inject([]) { result, value ->
result << alphabetIndices.find { it[0] == value }[1] + 1
result
}
assert positionInAlphabet == [7, 18, 15, 15, 22, 25]
Continue reading →
Groovy adds the pop
and push
methods to the List
class. With the pop
method we remove the last element of the list. And with the push
method we add an element to the end of the list.
def list = ['Groovy', 'is', 'great!']
// Remove last item from list
// with pop().
assert list.pop() == 'great!'
assert list == ['Groovy', 'is']
// Remove last item
// which is now 'is'.
list.pop()
// Add new item to end of
// the list (equivalent for add()).
list.push('rocks!')
assert list == ['Groovy', 'rocks!']
Continue reading →
In Groovy we can use the head
and tail
methods for a long time on Collection
objects. With head
we get the first element and with tail
the remaining elements of a collection. Since Groovy 2.4 we have a new method init
which returns all elements but the last in a collection.
In the following example we have a simple list and apply the different methods:
Continue reading →