Ask Your Question
4

How can aspectj-maven-plugin be incorporated into Bazel?

asked 2021-05-01 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-07-15 05:00:00 +0000

nofretete gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-01 11:00:00 +0000

Seen: 20 times

Last updated: Jul 15 '21