An open API service indexing awesome lists of open source software.

https://github.com/lefou/mill-aspectj

AspectJ compiler/weaver support for mill build tool
https://github.com/lefou/mill-aspectj

aspectj aspectj-plugin mill mill-plugin

Last synced: about 1 year ago
JSON representation

AspectJ compiler/weaver support for mill build tool

Awesome Lists containing this project

README

          

= mill-aspectj - AspectJ compiler support for mill
:version: 0.5.0
:projectHome: https://github.com/lefou/mill-aspectj
:minimal-mill-version: 0.9.3
:example-aspectj-version: 1.9.7
:example-scala-version: 2.13.11
:example-mill-platform-version: 0.11
:toc:
:toc-placement: preamble

Documentation for mill-aspectj, a mill plugin to support the https://github.com/eclipse/org.aspectj[AspectJ language and compiler].

== Quickstart

Mill version {minimal-mill-version} or newer is required.
Using the latest stable Mill release is recommended.

[source,scala,subs="attributes,verbatim"]
----
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::{version}`
import de.tobiasroeser.mill.aspectj._

object main extends AspectjModule {

// Select the AspectJ version
def aspectjVersion = "{example-aspectj-version}"

// 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 https://www.eclipse.org/aspectj/downloads.php[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
[source,scala,subs="attributes,verbatim"]
----
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::{version}`
import de.tobiasroeser.mill.aspectj._

object main extends ScalaModule with AspectjModule {

def scalaVersion = "{example-scala-version}"

// Select the AspectJ version
def aspectjVersion = "{example-aspectj-version}"

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

.Version Compatibility Matrix
[options="header"]
|===
| 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 {projectHome}/issues[issue].

== Download

You can download binary releases from https://search.maven.org/artifact/de.tototec/de.tobiasroeser.mill.aspectj_mill{example-mill-platform-version}_2.13[Maven Central].

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

== License

This project is published under the https://www.apache.org/licenses/LICENSE-2.0[Apache License, Version 2.0].

== Supporters

Thanks to https://iba-cg.de/[iba Consulting Gesellschaft mbH & Co KG] for the initial development support.

== About

Mill::
https://github.com/lihaoyi/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 https://github.com/lefou/[Tobias Roeser], a professional software developer and love to create open source software.
I'm actively developing and maintaining Mill as well as https://github.com/lefou?utf8=%E2%9C%93&tab=repositories&q=topic%3Amill&type=&language=[several mill plugins].

If you like my work, please star it on GitHub. You can also support me via https://github.com/sponsors/lefou[GitHub Sponsors].
--

Contributing::
+
--
If you found a bug or have a feature request, please open a {projectHome}/issues[new issue on GitHub].
I also accept {projectHome}/pulls[pull requests on GitHub].

You can also ask question and join our discussion at the {projectHome}/discussions[GitHub Discussions board]
--

== Changelog

=== 0.5.0 - 2023-06-24
:version: 0.5.0
:prev-version: 0.4.0
:github-milestone: 5

* Support Mill 0.11 API
* Dropped support for Mill versions older than `0.9`
* Tooling and Dependency updates

_See
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.4.0 - 2022-05-20
:version: 0.4.0
:prev-version: 0.3.2
:github-milestone: 4

* 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
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.3.2 - 2022-01-16
:version: 0.3.2
:prev-version: 0.3.1
:github-milestone: 3

* Support for newer mill APIs
* AspecjJ worker is only initialized when needed
* Improved test suite
* Various dependency version updates

_See
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.3.1 - 2020-06-15
:version: 0.3.1
:prev-version: 0.3.0
:github-milestone:

* 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
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.3.0 - 2020-03-04
:version: 0.3.0
:prev-version: 0.2.2
:github-milestone: 2

* 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
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.2.2 - 2020-02-24
:version: 0.2.2
:prev-version: 0.2.1
:github-milestone:

* Version bump mill API to 0.6.0

_See
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.2.1 - 2020-02-24
:version: 0.2.1
:prev-version: 0.2.0
:github-milestone:

* Version bump mill API to 0.5.8

_See
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.2.0 - 2020-01-08
:version: 0.2.0
:prev-version: 0.1.0
:github-milestone: 1

* Share ajc compiler instance between module
* Version bump mill API to 0.5.7

_See
ifeval::["{github-milestone}" != ""]
https://github.com/lefou/mill-aspectj/milestone/{github-milestone}?closed=1[milestone {version}]
and the
endif::[]
https://github.com/lefou/mill-aspectj/compare/{prev-version}\...{version}[list of commits]_

=== mill-aspectj 0.1.0 - 2019-08-30

* Initial public release