Groovy
Map with Default
I found the withDefault
operator while migrating a Grails plugin to Grails 4. I was not aware of it.
def m = [:].withDefault { key ->
new Date().toString()
}
String firstAccess = m['foo']
String secondAccess = m['foo']
assert firstAccess != null
assert firstAccess == secondAccess
Create a List with Default Values
Yes, there is a withDefault
for List to.
Since Groovy 1.8.7 we can create a list and use the withDefault() method to define a default value for elements that are not yet in the list. We use a closure as argument of the method, which returns the default value. We can even access the index of the element in the closure as an argument.
Micronaut
Player 2 Ready: Micronaut, a Spring Boot competitor
Hilarious deck by @ipreferespresso with Mario and Lugigi as leading characters. Mario is Spring Boot, Lugigi is Micronaut. The rest of the story you must read on your own.
Gradle
Task Timeouts
New in Gradle 5:
Every task has a timeout property which can be used to limit its execution time. When a task reaches its timeout, its task execution thread is interrupted. The task will be marked as failed.
Yup, we are working to ship Grails 4 with Gradle 5.
Java
Java 8 Cheatsheet
Grails 4 removes support for Java 7. This cheatsheet is a refresher about Lambdas and the stream API. It is not the Groovy Collection API but working with Java and the stream API feels nice.
Java 8 to Java 11
Grails 4 supports Java 11. In fact, we are configuring travis to run every build in both Java 8 and 11.
This cheatsheet is useful on its own but go ahead and read the companion blog post: From Java 8 to Java 11 in single stop by @venergiac.
DevOps
Skipping a build - Travis
If you don’t want to run a build for a particular commit for any reason, you may instruct Travis CI to skip building this commit via a command in the commit message.
To build micronaut, grails projects and documentation we use travis heavily. I am ashamed how many ci builds I triggered for silly changes. E.g. README typo fixes.
[ci skip]
Skipping the Installation Phase - Travis CI
You may not be aware but by default Travis runs assemble
.
Before running the build, Travis CI installs dependencies:
gradle assemble
If you want to disable the install
step, set:
install: true
Comment
Last week, I was immerse in Grails 4 development. This week, I will be pushing the Grails 4 wagon forward as well. Grails 4 removes support for Java 1.7. and will ship with Hibernate 5.3, Spring Boot 2.1, Gradle 5, Geb 2.2, Spock 1.2. Exciting times for Grails 4!
Sergio del Amo