Scalameta: A Scala Toolkit for Parsing, Transforming, and Generating Code
Library to read, analyze, transform and generate Scala programs. Tutorial If you'd like to find out how to use scalameta, see this tutorial.
At a glance
- What is it?
- Scalameta is a BSD-licensed library for reading, analyzing, transforming, and generating Scala programs. This review covers its core architecture, practical usage, and the trade-offs you should weigh before adopting it.
- Who is it for?
- Adopt Scalameta if you build tools that must parse or rewrite Scala source code, such as linters, formatters, or refactoring plugins. Skip it if you only need lightweight syntax checks or if your project targets Scala.js or Scala Native exclusively, as the material does not confirm full platform support.
- Can I use it commercially?
- Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Scala, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
What Scalameta Solves and Who Needs It
Scalameta addresses a gap in the Scala ecosystem: a unified library to read, analyze, transform, and generate Scala programs. Without it, a developer building a custom linter or a code generator would have to write their own parser, which is a large and error-prone task. The library targets tool authors, not application developers. If you work on an IDE plugin, a refactoring tool, a documentation generator, or a style checker, Scalameta gives you a structured way to handle Scala source code as data. The README does not list specific user stories, but the project's own description makes the intent clear. It is for people who need to treat code as something to inspect and modify programmatically, not just compile.
The Core Mechanism: A Full Scala AST and Transformation API
The central idea is that Scalameta parses Scala source into an abstract syntax tree (AST) that you can traverse, query, and rewrite. The README does not include a code sample, but the official tutorial, linked from the repository, walks through the basic flow. Based on the project's description, the library provides a tree structure where each node represents a syntactic construct, such as a class definition, a method call, or a literal. You can analyze this tree to find patterns, and you can transform it to produce modified code. The generation side means you can also build new Scala code from scratch by constructing tree nodes programmatically. This is different from string-based manipulation, because the tree retains semantic structure, so transformations are less likely to break syntax. The library also supports quasiquotes, a feature common in Scala metaprogramming, which lets you pattern-match on code snippets in a concise syntax, though the README does not confirm the exact quasiquote syntax.
Getting Started: Installation and Basic Usage
The README points to the user documentation at scalameta.org and a dedicated tutorial at http://scalameta.org/tutorial. It does not list a specific sbt dependency string, but the standard way to add a library to a Scala project is through sbt or Mill. For a typical sbt project, you would add a line like "org.scalameta" %% "scalameta" % "4.17.3" to your build.sbt, based on the latest release version shown in the repository metadata. The tutorial on the website likely shows how to parse a string into a tree and then print it back. The README does not include a command to run, so you would need to consult the tutorial for a concrete example. The project is published on Maven Central, as is common for Scala libraries, but the README does not mention the exact coordinates. You should check the tutorial for the current artifact name and version.
A Genuine Limitation: Version Coupling and API Stability
One limitation is that Scalameta's AST and API are tied to the Scala language version. The parser must understand the syntax of the Scala version you are analyzing. If you need to support multiple Scala versions, you may need to use different versions of Scalameta or handle dialect differences. The README does not specify which Scala versions are supported, but the project's release history (v4.17.3, v4.17.2, v4.17.1) suggests active maintenance, yet each release could bring changes to the AST. That means a tool built on Scalameta may break when the library updates, requiring you to update your code. Another limitation is that the library does not provide semantic analysis, such as type resolution or name binding. It is a syntactic tool. If you need to know the type of an expression or resolve a method call to its definition, Scalameta alone is not enough. You would need to combine it with the Scala compiler's internal API or another tool like SemanticDB.
When Scalameta Is the Wrong Tool
Scalameta is not a fit for every code-processing task. If you only need to check whether a file is syntactically valid, you could use the Scala compiler directly, which is faster and already in your build. If you need to perform type-aware refactoring, such as renaming a method across a codebase while respecting overloads, Scalameta's syntactic tree is insufficient. It cannot tell you that two identifiers refer to the same symbol. That requires a semantic model. Also, if you need to process Scala 3 source code, you must check whether Scalameta's current version supports the Scala 3 dialect. The README does not mention Scala 3 explicitly, so you should verify compatibility before relying on it for modern Scala projects. For simple string manipulation or regex-based code changes, a full AST is overkill and adds a dependency with a learning curve.
A Real Alternative: The Scala Compiler's Internal API
The most direct alternative is to use the Scala compiler's own API, often referred to as the compiler internals or nsc. The compiler provides a full syntactic tree and also a semantic layer with symbols and types. This means you can resolve names and get type information, which Scalameta cannot do. The trade-off is that the compiler API is internal, unstable across Scala versions, and not designed for general consumption. It is also much heavier to run, because you must invoke the compiler pipeline. Scalameta offers a cleaner, stable API at the cost of losing semantic information. Another alternative is SemanticDB, which is a data model for semantic information about Scala code, but it is not a parser itself; it is produced by the compiler. Scalameta is often used together with SemanticDB, but they are separate projects. If you need both syntax and semantics, you might use Scalameta for parsing and then query SemanticDB for type information, but that adds complexity.
Maintenance and Upgrade Cost
The repository shows active development, with the latest release v4.17.3 pushed on 2026-07-24. The project has a team of named maintainers, which is a positive sign for long-term support. However, the README does not describe a migration guide or a policy for API stability. Based on the version number 4.x, the project is past its initial development, but minor releases can still introduce breaking changes. When you upgrade Scalameta, you should expect to recompile your code and possibly adjust to AST changes. The license is BSD-3-Clause, which is permissive and allows commercial use, modification, and redistribution, provided you retain the copyright notice. This is a low-license-risk library, but you should still review the full license text in the repository. There is no mention of a separate contribution guide or a code of conduct in the README, but the maintainers list suggests a community-driven project. For a production tool, you should pin the exact version you use and test upgrades in a separate branch.
Editorial conclusion
Adopt Scalameta if you build tools that must parse or rewrite Scala source code, such as linters, formatters, or refactoring plugins. Skip it if you only need lightweight syntax checks or if your project targets Scala.js or Scala Native exclusively, as the material does not confirm full platform support. Before committing, verify the version compatibility with your target Scala compiler versions, since the library's AST and APIs shift across releases. Also confirm that the BSD-3-Clause license fits your distribution model; it permits commercial use but requires retaining the copyright notice. Start by running the tutorial from scalameta.org to see if the API matches your use case, then test on a representative corpus of your own code before integrating into a production pipeline.
Community notes