Skip to content

lefou/mill-aspectj

Repository files navigation

mill-aspectj - AspectJ compiler support for mill

Quickstart

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")

}

Configuration

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 use super.ivyDeps() when overriding this def, you need to provide the aspectjrt.jar manually.

def aspectjToolsDeps: T[Agg[Dep]]

The ivy dependencies representing the aspectj compiler classes, which is typically a aspectjtools.jar. Default to ivy"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 the compile 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 use aspectModuleDeps and aspectIvyDeps.

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 use aspectModuleDeps and aspectIvyDeps.

def weavePath: T[Seq[PathRef]]

List of directories with .class files to weave (into target directory). Corresponds to ajc -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).

Mixing in the Aspectj-Compiler in an existing Compiler chain (aka Scala support)

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.

Example for chained compilation setup: First Zinc, then AspectJ
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
}

Version Compatibility Matrix

The following table shows a matrix of compatible mill and mill-aspectj versions.

Table 1. Version Compatibility Matrix
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.

Download

You can download binary releases from Maven Central.

Please make sure to use the correct mill platform suffix matching your used mill version.

License

This project is published under the Apache License, Version 2.0.

Supporters

Thanks to iba Consulting Gesellschaft mbH & Co KG for the initial development support.

About

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

Changelog

0.5.0 - 2023-06-24

  • Support Mill 0.11 API

  • Dropped support for Mill versions older than 0.9

  • Tooling and Dependency updates

mill-aspectj 0.4.0 - 2022-05-20

  • 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.

mill-aspectj 0.3.2 - 2022-01-16

  • Support for newer mill APIs

  • AspecjJ worker is only initialized when needed

  • Improved test suite

  • Various dependency version updates

mill-aspectj 0.3.1 - 2020-06-15

  • 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

mill-aspectj 0.3.0 - 2020-03-04

  • 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

mill-aspectj 0.2.2 - 2020-02-24

  • Version bump mill API to 0.6.0

mill-aspectj 0.2.1 - 2020-02-24

  • Version bump mill API to 0.5.8

mill-aspectj 0.2.0 - 2020-01-08

  • Share ajc compiler instance between module

  • Version bump mill API to 0.5.7

mill-aspectj 0.1.0 - 2019-08-30

  • Initial public release