Micronaut Configuration for CLI

In my previous post we saw how to create a service using micronaut CLI. When you create an application/project using the CLI command mn, the preferences you entered are saved in a file named 'micronaut-cli.yml', which can be found at the project top level directory. Let's take a look at the file from our 'hello-word' service.

profile: service
defaultPackage: hello.service
---
testFramework: junit
sourceLanguage: java

Profile

By default Micronaut uses the service profile while you create a project using  the create-app command. The profile decides what capabilities to be made available in the project including dependencies, CLI commands to be made available to the developers and the templates for generating code (For example we created a controller using the create-controller command, which was part of the service profile. The templates include the controller and test classes for the controller).

The CLI provides a nice autocompletion when you generate your project. Below are the options for the profile.

mn> create-app --profile

base           cli            federation     function       function-aws   kafka          profile        service

If you are an enterprise and multiple teams will have to create services with similar structure, creating a custom profile for your enterprise will be a handy option.

Default package

The value for the default package 'hello.service' is derived from the service name we supplied 'hello-service'. One can make out that by replacing hyphens with dots, the CLI arrived at the default value. You could go ahead and change it with the desired value so that the subsequent commands consider the new value for the default package.

If you prefix your service with a package name during the creation of the service using create-app command, the corresponding package name will be considered default.

create-app com.nareshak.hello-service

The above command will create hell-service and the default package to com.nareshak

Test framework

The default test framework for a java project is 'junit'.

I was surprised to find JUnit 4 instead of JUnit 5.

Spock (default for Groovy projects) and Spek (for Kotlin projects) are other supported test frameworks. These values will be used for choosing the appropriate templates for the test classes.

Source Language

Source language can be supplied while creating your project using the create-app command.

mn> create-app --lang

java     groovy   kotlin

Java is the default language. You can choose Groovy or Kotlin, if you wish.

The test framework and source language options are inter-related. If you choose groovy language, Spock will be the test framework. On the other hand if you add Spock as a feature (using --features spock option), language will be set to groovy.

Show Comments