I am using AspectJ 1.9.7 and I am trying to compile a modular application with ajc. Let's suppose I have a single module called test and the following tree:
.
└── test
├── aspectj
│ ├── Main.java
│ └── TestAspect.aj
└── module-info.java
With javac the command I would use to compile it is:
javac --module-source-path . -d ../bin -m test
And everything works fine, of course without the weaving process. Instead, if I try to run the same line with ajc (ajc --module-source-path . -d ../bin -m test), the output is:
[error] build config error: dir arg not permitted: test
[error] unrecognized single argument: "-m"
[error] no sources specified
3 errors
I guess at this point that the -m option is not supported. I have found this question, where a user says that it is possible to specify the option -usejavac to use javac in the compilation process but, at least for me, does not work and the option is not even recognized.
1) How to use --module-source-path with ajc?
Assuming --module-source-path is not supported, I have opted for the --module-path option. Again, with javac, everything ok:
javac -d bin --module-path test $(find . -name *.java)
But switching to ajc (ajc -d bin --module-path test $(find . -name *.java -o -name *.aj)), the output is this:
/home/maluz/Desktop/OneDrive/First Semester/TSP/labs/lab2/Test/test/module-info.java:1 [error] Syntax error on token "module", aspect expected
module test {
^^^^^
1 error
Same output when I remove --module-path.
2) Is there a way to compile a module with ajc?
The alternative would be something like:
# I compile every *.java and *.aj except module-info.java with ajc
$ ajc -d bin $(find . \( -name *.java -o -name *.aj \) -and \( -not -name *module-info.java \))
# I compile module-info.java separately with javac
$ javac --module-path test -d bin/ test/module-info.java
It works but there must be a way to do it with ajc, given that --module-path and --module-source-path are documented under the Module compilation options of ajc man. I am not sure this is relevant, but I am using openjdk 15.0.2 2021-01-19.