Turn Any Repo Into a Software Factory: Exploring Spring 5 and Kotlin

Rod Johnson
The Composition
Published in
3 min readOct 27, 2017

Thanks to Josh Long @starbuxman

Spring 5.0 is arguably the most important Spring release since 1.0.0, back in 2004. Two of the key new features are the support for reactive programming and comprehensive support for Kotlin.

My friend Josh Long’s enthusiasm for both of these caught my imagination, especially as I hadn’t yet played with Kotlin. So I thought I’d use a repo Josh created as a seed for an Atomist generator.

Now that there’s a generator, you too can make your own custom Spring 5 Kotlin projects.

Using an Atomist Generator: How the Parts Fit Together

Atomist project creation takes a starting point called a seed project and runs a TypeScript project generator to transform it into a new, customized project, based on user parameters. The seed project is a normal project, usually a GitHub repository, so you can build and edit it with normal tooling. The diagram shows how the combination works:

The transformation of the seed project is a special case of project editing, another core Atomist concept. For a fuller description, see my previous blog.

The Seed Project

The project itself is a Kotlin Spring 5 app, using Spring Boot 2.0.0.M5. The README provides a good introduction to the moving parts. See also one of Josh’s excellent presentations on reactive Spring here. The most interesting points are the use of the new reactive web framework and the demonstration of Spring 5.0’s extensive support for Kotlin — in this case, the routing DSL.

The project isn’t changed in any way to serve as an Atomist seed. No dark template magic — nothing but Kotlin and Maven.

The Generator: Transforming the Seed

You could clone or fork the seed, but ideally you want your own, distinct, project, with its own Maven artifact identification, root package, etc. and a clean git history.

To make this transformation available to people on the web, in Slack, and via REST, we implement a command handler: an Atomist automation that is invoked in response to a user command, collecting whatever parameters it needs. Generators are just one type of command handler.

In this case we can extend the TypeScriptJavaSeed class from our automation-client library, which defines parameters for creating Java/JVM apps such as rootPackage and artifactId, as well as parameters common to all generators, such as the organization and name of the repository to create.

Our subclass is annotated to identify itself to the Atomist infrastructure. It fills in some parameters on the superclass to change the default seed, and implements the abstract projectEditor method to return a project editor: that is, a function that transforms the seed into a fresh project. The superclass takes care of loading the seed project and creating a GitHub repository for the new project:

The implementation of transformSeed works with the Atomist Project and File abstractions, which provide a storage-independent view of files in a repository. (In keeping with Spring’s own philosophy, this abstraction facilitates testing.)

In my next post I’ll go into the details of transformSeed and show how to write unit and integration tests. The full code is here.

Next Steps

If you’ve authenticated Atomist in your Slack team, you can run it via Slack:

You can use this approach to turn any repository into a software factory. Spring/Kotlin is just one possibility.

To learn more:

  • Point the generator at a different Spring Boot/Kotlin source repository. (Or raise a PR on the existing seed! When merged, new projects will immediately reflect the changes.) This allows lots of customization without coding. For example, you can use a seed that contains unique code and configuration for your organization , and evolve it without fear.
  • Clone the generator to get it running locally and change its behavior. Try adding and modifying other files, or perform additional actions like making API calls.

In Part II, I’ll explain how the generator works in detail. In future blogs, I’ll talk about how Atomist can help you to evolve Spring programs, as well as create them.

--

--

Rod Johnson
The Composition

Cofounder and CEO, Atomist. Creator of Spring, Cofounder/CEO at SpringSource (acq by VMW)