Documentation for mill-aspectj, a mill plugin to support the AspectJ language and compiler.
Mill version 0.9.3 or newer is required. Using the latest stable Mill release is recommended.
import mill._
import mill.scalalib._
import mill.define._
// Load the plugin from Maven Central via ivy/coursier
import $ivy.`de.tototec::de.tobiasroeser.mill.aspectj::0.5.0`
import de.tobiasroeser.mill.aspectj._
object main extends AspectjModule {
// Select the AspectJ version
def aspectjVersion = "1.9.7"
// Set AspectJ options, e.g. the language level and annotation processor
// Run `mill main.ajcHelp` to get a list of supported options
def ajcOptions = Seq("-8", "-proc:none")
}
Your module needs to extend de.tobiasroeser.mill.aspectj.AspectjModule
which itself extends mill.scalalib.JavaModule
.
The module trait de.tobiasroeser.mill.aspectj.AspectjModule
has the following configuration options (over those from mill.scalalib.JavaModule
).
def aspectjVersion: T[String]
-
The AspectJ version. Required. For a list of available releases refer to the AspectJ Download Page.
def ivyDeps: T[Agg[Dep]]
-
The compile and runtime dependencies. Contains by default the
aspectjrt.jar
which is resolved via ivy (ivy"org.aspectj:aspectjrt:${aspectjVersion()}"
). If you do do not usesuper.ivyDeps()
when overriding this def, you need to provide theaspectjrt.jar
manually. def aspectjToolsDeps: T[Agg[Dep]]
-
The ivy dependencies representing the aspectj compiler classes, which is typically a
aspectjtools.jar
. Default toivy"org.aspectj:aspectjtools:${aspectjVersion()}"
. def aspectjToolsClasspath: T[Agg[PathRef]]
-
The aspectj compiler classpath. By default resolved from
aspectjToolsDeps
. def ajcOptions: T[Seq[String]]
-
Additional options to be used by
ajc
in thecompile
target. def aspectPath: T[Agg[PathRef]]
-
Additional classes, JARs or ZIPs to be used as aspect path (
ajc -aspectpath
). In most cases it is enough to useaspectModuleDeps
andaspectIvyDeps
. def aspectModuleDeps: Seq[JavaModule]
-
List of modules to be used as aspect path (
ajc -aspectpath
). def aspectIvyDeps: T[Agg[Dep]]
-
List of ivy dependencies to be used as aspect path (
ajc -aspectpath
). def effectiveAspectPath: T[Seq[PathRef]]
-
Effective aspect path (
ajc -inpath
). In most cases, it is enough to useaspectModuleDeps
andaspectIvyDeps
. def weavePath: T[Seq[PathRef]]
-
List of directories with
.class
files to weave (into target directory). Corresponds toajc -inpath
option. def compile: T[CompilationResult]
-
Compiles the source code with the ajc compiler.
def ajcHelp: Command[Unit]
-
Shows the help of the AspectJ compiler (
ajc -help
).
If you override the def aspectjCompileMode
to return CompileMode.OnlyAjSources
, you can chain the AspectJ compiler after another compiler.
In this setup, the AspectJ compiler will not compile your Java source files but weave-compiles the already compiled classes.
Only the *.aj
files (if any) are fed as source files. All other
inputs (the already compiled classes) are fed via the -inpath
option.
With this setup, we can even compile-time weave Scala (and probably also Kotlin or other JVM language) classes. But this only works reliably with Mill 0.10.0 and newer.
import mill._
import mill.scalalib._
import mill.define._
// Load the plugin from Maven Central via ivy/coursier
import $ivy.`de.tototec::de.tobiasroeser.mill.aspectj::0.5.0`
import de.tobiasroeser.mill.aspectj._
object main extends ScalaModule with AspectjModule {
def scalaVersion = "2.13.11"
// Select the AspectJ version
def aspectjVersion = "1.9.7"
// Set AspectJ options, e.g. the language level and annotation processor
// Run `mill main.ajcHelp` to get a list of supported options
def ajcOptions = Seq("-8", "-proc:none")
// other settings
}
The following table shows a matrix of compatible mill and mill-aspectj versions.
mill-aspectj | mill |
---|---|
0.5.0 |
0.9.0 - 0.11.x |
0.4.0 |
0.6.0 - 0.10.x |
0.3.2 |
0.6.0 - 0.10.x |
0.3.1 |
0.6.0 - 0.8.0 |
0.3.0 |
0.6.0 - 0.6.3 |
0.2.2 |
0.6.0 - 0.6.3 |
0.2.1 |
0.5.8 - 0.5.9 |
0.2.0 |
0.5.7 |
0.1.0 |
0.3.6 - 0.5.3 |
To ensure some basic compatibility, there are some integration tests in place. Newer mill versions may work as well.
If you need support for other versions, please create an issue.
You can download binary releases from Maven Central.
Please make sure to use the correct mill platform suffix matching your used mill version.
This project is published under the Apache License, Version 2.0.
Thanks to iba Consulting Gesellschaft mbH & Co KG for the initial development support.
- Mill
-
Mill is a Scala-based open source build tool. In my opinion the best build tool for the JVM. It is fast, reliable and easy to understand.
- Me
-
I am Tobias Roeser, a professional software developer and love to create open source software. I’m actively developing and maintaining Mill as well as several mill plugins.
If you like my work, please star it on GitHub. You can also support me via GitHub Sponsors.
- Contributing
-
If you found a bug or have a feature request, please open a new issue on GitHub. I also accept pull requests on GitHub.
You can also ask question and join our discussion at the GitHub Discussions board
-
Support Mill 0.11 API
-
Dropped support for Mill versions older than
0.9
-
Tooling and Dependency updates
See milestone 0.5.0 and the list of commits
-
Support chained compilation to run AspectJ compiler after Zinc or other compilers
-
New
aspectjCompileMode
config option, to configure Aspectj compiler behavior, e.g. to weave-compile already compiled classes.
See milestone 0.4.0 and the list of commits
-
Support for newer mill APIs
-
AspecjJ worker is only initialized when needed
-
Improved test suite
-
Various dependency version updates
See milestone 0.3.2 and the list of commits
-
Support for mill API 0.7.x and Scala 2.13
-
Switch to GitHub Actions workflow and removed Travis CI setup
-
Enabled auto-deployment of tagged and snapshot releases to Maven Central
See list of commits
-
Splitted out new api and worker package to access Aspectj Java API instead of reflection
-
Removed need to use a Java SecurityManager to trap
System.exit()
calls -
Made concurrent runs of the compiler configurable
-
Fixed
ajcHelp
task -
Support for Java 11 and others
See milestone 0.3.0 and the list of commits
-
Share ajc compiler instance between module
-
Version bump mill API to 0.5.7
See milestone 0.2.0 and the list of commits