In Groovy 2.5.0 we can use a Java 8 Optional
object in a conditional context.
When an Optional
object has a value the value is coerced to true
and when empty the value is false
.
Written with Groovy 2.5.0.
Continue reading →
We can use ranges in Groovy using an easy syntax where the start and end values of the range are separated by ..
for an inclusive range and ..<
for an exclusive range as we have seen in a previous post.
The values of the range are mostly numbers or enum
values.
But we can also use String
values to define a range.
Groovy will check if the String
values are the same length and if the values, except for the last character, are the same.
Then the natural ordering of the last character of the String
value, based on the character’s int
value, is used to create the range values.
In the following example we define several ranges using String
values. We can even define a reverse range using String
values.
Continue reading →
Groovy has support for defining ranges in the language.
When we define a range of numbers the steps between the values in the range is 1
by default.
We can change the step size using the step
method.
This method accepts a int
value with a new step size.
The result is a List
object with the values.
Since Groovy 2.5.0 the by
method is added to ranges with numbers.
The by
method accepts also decimal numbers and the result of the method is a NumberRange
object instead of a List
.
In the following example Groovy script we first define a range with int
values.
We use the by
method to change the step size using both an int
value and BigDecimal
value.
We also use the by
method for a range of BigDecimal
numbers:
Continue reading →
To use an icon from the icon set we must include the icon using the !include
statement.
In our PlantUML definition we reference the icon with the syntax <$iconName>
.
In the following example PlantUML definition we include 2 icons from the Font Awesome and Devicons icon sets:
Continue reading →
PlantUML mostly does a good job organizing elements and arrows in the resulting diagram.
But we can help PlantUML by defining the arrow direction in our PlantUML definition.
We can use the keywords up
, down
, left
and right
inside the arrow definition.
In the following example we have five rectangles connected with arrows.
We define the arrow direction for each arrow.
Continue reading →
One of the command line options of Gradle is --offline
.
With this option we run Gradle in offline mode to indicate we are not connected to network resources like the internet.
This could be useful for example if we have defined dependencies in our build script that come from a remote repository, but we cannot access the remote repository, and we still want to run the build.
Gradle will use the locally cached dependencies, without checking the remote repository.
New dependencies, not already cached, cannot be downloaded of course, so in that scenario we still need a network connection.
We can check in our build script if the --offline
command line argument is used.
We can use this to disable tasks that depend on network resources so the build will not fail.
To see if we invoked our build with the --offline
option we can access the property gradle.startParameter.offline
.
The value is true
if the command line argument --offline
is used and false
if the command line argument is not used.
Continue reading →
Gradle added an incubation feature to Gradle 4.6 to add command line options for custom tasks.
This means we can run a task using Gradle and add command line options to pass information to the task.
Without this feature we would have to use project properties passed via the -P
or --project-property
.
The good thing about the new feature is that the Gradle help
task displays extra information about the command line options supported by a custom task.
To add a command line option we simply use the @Option
annotation on the setter method of a task property.
We must make sure the argument for the setter method is either a boolean
, Boolean
, String
, enum
, List<String>
or List<enum>
.
The @Option
annotation requires an option
argument with the name of the option as it must be entered by the user.
Optionally we can add a description
property with a description about the option.
It is good to add the description, because the help
task of Gradle displays this information and helps the user of our custom task.
Continue reading →
With the Asciidoctor diagram extension we can include diagrams that are written in plain text.
For example PlantUML or Ditaa diagrams.
The extension offers a block processor where we include the diagram definitions in our Asciidoctor document.
But there is also a block macro processor. With the block macro processor we can refer to an external file.
The file is processed and the resulting image is in our output document.
In the following example we see how to use the block macro for a Ditaa diagram:
Continue reading →
In our Groovy scripts we can use the @Grab
annotation.
With this annotation we define dependencies for our script and they will be automatically downloaded and added to the class path when we run our script.
When we use IntelliJ IDEA we can use a nice intention that is part of the IntelliJ IDEA Groovy support to download the dependencies from our IDE editor.
IDEA downloads the dependencies and add it to the project module dependencies.
This is useful, because this will also adds code completion for the classes in the dependency to our editor.
Let’s see this with a little example. We have the following Groovy script in our Groovy project in IntelliJ IDEA:
Continue reading →
PlantUML has a built-in icon set we can use in our diagram definitions.
The icon set is open source icon set OpenIconic.
We refer to an icon using the syntax <&iconName>
.We can use an icon everywhere where we can use text in our diagrams.
In the following example we use different icons in different places:
Continue reading →
PlantUML supports sprites to be used in diagrams.
A sprite is text encoded monochrome graphic we can reference using the syntax <$spriteName>
.
The sprite is defined using hexadecimal values.
We can define a set of hexadecimal values to create our sprite, but we can also generate the correct values from for example a PNG image.
We start with a simple example where we create a small triangle using hexadecimal values:
Continue reading →
In a previous post we learned how to use a together
block to keep elements together.
We can also layout elements in a different way: using hidden lines.
We define our elements and by using the keyword [hidden]
in our line definition the elements are layout as if there was a line, but we don’t see it.
This gives us great flexibility on how we layout our elements.
In the following sample we first have a PlantUML definition where we rely on the default layout:
Continue reading →