The dw::core::Strings
module has useful functions for working with string values. One of the functions is dasherize
. The function takes a string argument and replaces spaces, underscores and camel-casing into dashes. The resulting string value with hyphens is also called kebab-casing. The dasherize
function also turns any uppercase character to lowercase.
Continue reading →
When we are working with a multi-module project in Maven we might want to exclude a module when we invoke a build command. We might only be interested in partially building some modules. We can use the command line option -pl
or --projects
to specify a list of modules that need to be in our build. But we can also use !
followed by the module name to exclude modules from our build.
Continue reading →
The version catalog in Gradle is very useful to define a list of dependencies in one single place. In our build script we references dependencies from the version catalog using type safe accessors when we define a dependency for a configuration. Sometimes multiple dependencies belong to each other and are used in combination with each other. In the version catalog we can define bundles of such dependency groups. Instead of referencing each dependency individually we can reference a bundle from the version catalog in our build script. This keeps our build script cleaner and updating a bundle only needs a change in the version catalog.
Continue reading →
A version catalog in Gradle is a central place in our project where we can define dependency references with their version or version rules. A dependency reference is defined using an identifier with a corresponding dependency definition containing the coordinates of the dependency. Now we can reference the dependency using the identifier in for example a dependency configuration, e.g. implementation(libs.spring.core)
. If there is a version change we want to apply we only have to make the change in our version catalog. An added bonus is that Gradle generates type safe accessors for the identifier we use in our version catalog, so we can get code completion in our IntelliJ IDEA when we want to reference a dependency from the version catalog.
Besides dependencies we need to build and test our software we can also include definitions for Gradle plugins including their version.
Continue reading →
In a previous post we learned how to read text file contents with the slurp
function. To write text file content we use the spit
function. We content is defined in the second argument of the function. The first argument allows several types that will turn into a Writer
object used for writing the content to. For example a string argument is used as URI and if that is not valid as a file name of the file to read. A File
instance can be used directly as argument as well. But also Writer
, BufferedWriter
, OutputStream
, URI
, URL
and Socket
. As an option we can specify the encoding used to write the file content using the :encoding
keyword. The default encoding is UTF-8 if we don’t specify the encoding option. With the option :append
we can define if content needs to be appended to an existing file or the content should overwrite existing content in the file.
Continue reading →
The slurp
funtion in Clojure can be used to read the contents of a file and return it as a string value. We can use several types as argument for the function. For example a string argument is used as URI and if that is not valid as a file name of the file to read. A File
instance can be used directly as argument as well. But also Reader
, BufferedReader
, InputStream
, URI
, URL
, Socket
, byte[]
and char[]
. As an option we can specify the encoding used to read the file content using the :encoding
keyword. The default encoding is UTF-8 if we don’t specify the encoding option.
Continue reading →
DataWeave has some very nice features to transform data objects. One of those nice features is the update
operator. With the update
operator we can change values of keys in an object using a very concise syntax. We don’t have to go through all keys and create a new object, but we can pinpoint the exact key and change the value. To get the correct key we use selectors. Once we have the key we can set a new value. We can define a variable to contain the current value if we want to use it to define a new value. Also is it possible to add a condition that needs to be true to change the value. Finally the update
operator supports upserting a value if the key might not exist yet.
Continue reading →
In a previous post we learned about the macros SV
, SVI
and SVD
that return a string representation of variables with their name and value. Groovy 4 also added the NP
and NPL
macros that we can use to inspect variables. Instead of returning a GString
instance these macros return a NamedValue
instance or a list of NamedValue
value instances. The NamedValue
class is a simple class with a property name
, containing the name of the variable, and property val
with the value of the variable. The macro NP
can be used when we have a single variable and result is a single NamedValue
instance. An the macro NVL
can be used with multiple variables. The result is a list of NamedValue
instances where each instance represent a variable passed as argument to NVL
.
Continue reading →
Groovy 4 added some built-in macros that we can use in our code. A macro is code that will create new code. It does this by manipulating the Abstract Syntax Tree (AST) before the code is compiled. So when we use a macro, the macro will change the AST and those changes will be compiled. The three built-in macros SV
, SVI
and SVD
can create a GString
instance with the names and values of the variables that are passed as argument. This can be very useful to create some meaningful debugging statements. Normally we would have to type in the variable name ourselves followed by the value. Now with these macros we don’t have to type the variable as the macro will add that to the AST for us.
Continue reading →
DataWeave has a nice language feature called literal types. Literal types are types with a single predefined values and can be defined using a String
, Number
or Boolean
value. So the value of a literal type is a fixed value. We can combine multiple literal types into a new type using a union type to define an enumaration in DataWeave. The enumaration can only be one of the literal types used to define it.
Together with overloaded functions literal types are very useful. We can define a function where one of the input arguments is a literal type to define specific behaviour based on the literal type. Then we can overload the function for other literal types with different behaviour. DataWeave will make sure the correct function is called based on the value of the input argument and how it matches to the literal type value.
Continue reading →
Groovy supports ranges for a long time. But Groovy 4 adds a new feature for ranges and that is the support for open (exclusive) ranges at the beginning of a range. Open means the number that defines the range is not part of the actual range result and we must use the less-than character (<
). This is also referred to as exclusive, where the value is excluded from the range. When a range is closed the value is included, also called inclusive. Before Groovy 4 we could already define the end of the range to be exclusive or inclusive, but now we can also define the beginning of the range to be exclusive.
Continue reading →
SDKMAN! has a home
command that will return the absolute path of any SDK we pass as argument. This can be useful in scripts where we need the absolute path to a SDK. We can specify the name of the SDK after the home
command and the version. To use the current version that is set as default we can use as version current
.
Continue reading →