Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To incorporate aspectj-maven-plugin into Bazel, follow these steps:

  1. Download the aspectj-maven-plugin .jar file from a Maven repository.
  2. Copy the .jar file into your Bazel project's workspace.
  3. Add the following lines to your WORKSPACE file to declare a new Maven artifact:
maven_jar(
    name = "aspectj-maven-plugin",
    artifact = "org.codehaus.mojo:aspectj-maven-plugin:1.12.6",
    sha1 = "2f7dbdda13c584792028aaa9f1dcb2dae94dbf57",
)
  1. In your BUILD file, add a new aspectj_library target that depends on the maven artifact:
load("@maven//:defs.bzl", "maven_jar")

aspectj_library(
    name = "my_aspectj_target",
    srcs = glob(["**/*.aj"]),
    deps = [
        ":my_dependency",
        maven_jar("org.codehaus.mojo:aspectj-maven-plugin"),
    ],
)
  1. Update the build rule for any target that needs to apply the AspectJ aspect. For example, add the following to the build rule for a Java binary target:
java_binary(
    name = "my_binary",
    srcs = glob(["*.java"]),
    main_class = "com.example.MyClass",
    deps = [":my_aspectj_target"],
)
  1. Run your AspectJ aspect by building the binary target as usual:
bazel build //path/to/my_binary