We like to refer to Micronaut as a foundation framework. You can build web applications but you can build other kind of apps. In my case, I wanted a command line app. I created a CLI app with
micronaut create-cli-app. To get exchange rates, I run:
$ ./gradlew build
$ java -jar subprojects/cli/build/libs/cli-0.2-all.jar
05:51:20.472 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [cli]
Micronaut CLI apps use picocli and it has nice utilities such as completion candidates and converters which I use to get a nicer help output.
$ java -jar subprojects/cli/build/libs/cli-0.2-all.jar -help
05:54:50.855 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [cli]
Usage: exchangeratesapi [-hV] [--base=<base>] [--end=<endAt>]
Obtains Foreign exchange rates from https://exchangeratesapi.io
--base=<base> Base currency. Default Value: USD. Possible values:
AED, AFN, ALL, AMD, ANG, AOA,...
Since Micronaut 1.2, Micronaut has built-in support for validating beans that are annotated with javax.validation annotations.
Micronaut’s implementation includes the following benefits:
- Reflection and Runtime Proxy free validation resulting in reduced memory consumption.
- Smaller JAR size since Hibernate Validator adds another 1.4MB.
- Faster startup since Hibernate Validator adds 200ms+ startup overhead.
- Configurability via Annotation Metadata.
- Support for Reactive Bean Validation.
- Support for validating the source AST at compilation time.
- Automatic compatibility with GraalVM native without additional configuration.
I am using the @PastOrPresent Constraint to ensure I don't request rates for an invalid date.
With Spock, checking that the constraints are being validated is easy.