Kotlin coroutines, no-arg, and all-open

Oct 13, 2018 1 min read

My team uses this on every microservice repo we have as a default. This enables all classes having certain annotations to be generated as open, as well as creating a no-arg constructor.

You can remove the coroutine line if you don't use those.

We now use Micronaut for our microservices framework, and really just need our service and repository classes with @Singleton set to open classes, typically so proxies can be created.

      <plugin>
        <artifactId>kotlin-maven-plugin</artifactId>
        <groupId>org.jetbrains.kotlin</groupId>
        <version>${kotlin.version}</version>

        <configuration>
          <args>
            <arg>-Xcoroutines=enable</arg>
          </args>

          <compilerPlugins>
            <plugin>no-arg</plugin>
            <plugin>all-open</plugin>
          </compilerPlugins>

          <pluginOptions>
            <option>no-arg:annotation=javax.inject.Singleton</option>
            <option>no-arg:annotation=org.junit.runner.RunWith</option>
            <!-- Call instance initializers in the synthetic constructor -->
            <!--<option>no-arg:invokeInitializers=true</option>-->

            <option>all-open:annotation=javax.inject.Singleton</option>
            <option>all-open:annotation=org.junit.runner.RunWith</option>
          </pluginOptions>
        </configuration>

        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-noarg</artifactId>
            <version>${kotlin.version}</version>
          </dependency>

          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
      </plugin>

Join the conversation

Great! Next, complete checkout for full access to Brandon's Blog.
Welcome back! You've successfully signed in.
You've successfully subscribed to Brandon's Blog.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.