· 4 min read Posted by Gustavo Fão Valvassori
Amper: a new way to configure Gradle projects?
Earlier this month, JetBrains declared that Kotlin Multiplatform is stable. And just a couple of weeks later, JetBrains also announced a new tool to help with one of the biggest issues we have, configuration. Currently, KMP projects use Gradle as a Build System, and we must agree that it’s a great tool. But the complexity around it for new users is a big issue.
Amper is a tool to help you configure your projects using a markup language. The main goal is to replace the Groovy/Kotlin programming language with something that can enforce a declarative approach. With a declarative paradigm, you can only declare what needs to be done without implementing it. If you already have experience with Maven, it may be familiar to you.
Please note that the tool is in the early stages of development, and its goal is to validate the idea before putting more effort into it. With that in mind, be aware that syntax, language, and other things may change in the future, and it’s a very experimental tool.
How does it work?
According to the docs, Amper is implemented as a Gradle plugin and uses YAML for its project configuration format
. In
other words, it’s still a Gradle environment, but it will use an additional YAML file to configure the project. To be
able to use it, you need one of the following environments:
- Use one of the following IDEs:
- IntelliJ IDEA 2023.3 or newer and the Amper Plugin; or
- Fleet 1.26 or newer;
- Use the Amper build plugin to enable it:
- In your
settings.gradle.kts
, add this plugin:id("org.jetbrains.amper.settings.plugin").version("0.1.1")
- In your
When you open a project with the Amper Plugin in the IDE, it will look for the module.yaml
file. This file will contain
the configuration for the module (library or application), dependencies, and other project configurations (like the Java version).
Also worth noting that it also changes the project architecture. Instead of having a directory for your source-set
artifacts, you will have multiple src
directories. In other words, your commonMain/src/kotlin
will be only src
now, and your iosMain/src/kotlin
will be only src@ios
. This is a bit confusing at first, but it helps flatten the
project structure.
Our Thoughts
Amper comes to fix a huge problem for all KMP developers. We at Touchlab look forward to anything that will reduce the configuration complexity in KMP, and Amper is hopefully a step in the right direction. The Gradle team seems to be on board, at least with the concept. Hopefully the combined efforts will result in something that is truly easier to use and more maintainable.
The integration with the IDEs works fine for configuration. It knows the configuration schema and gives you valid suggestions for properties. Unfortunately, the configuration of the third-party plugins is not currently supported, but it’s on their roadmap.
The project APIs are small and only supports a short range of configurations. For basic contexts it works like a charm, but when you need to do something more complex, you may need to work with Gradle again.
The Gradle interop is great. You can still have a build.gradle.kts
file to make custom configurations that are not
available yet in the YAML file. One does not replace the other, but complement instead. This will be useful if you need
to create intermediate source-sets, configure plugins or even import libraries that have a different configuration.
For now, we recommend testing it it out on smaller projects that may not have a big impact with future changes, as it’s still experimental. But we are excited to see how it will evolve in the future. If you are using it, don’t forget to share your opinions with the JetBrains team on their Feedback Form and their Slack Channel.