You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IDE.md 6.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Setting up an AspectJ development environment
  2. _by Alexander Kriegisch, 2021-08-05_
  3. AspectJ, being an Eclipse project, can of course be used in the Eclipse IDE for Java developers, if you also install the
  4. AspectJ Development Tools (AJDT). IntelliJ IDEA also offers AspectJ and Spring AOP support. Regarding build tools, there
  5. are AspectJ plugins for Maven, Gradle and Ant.
  6. Of course, you can use and other IDE and build tool or simply use your trusted text editor of choice and compile using
  7. the AspectJ Compiler _ajc_ from the command line.
  8. Please refer to the [AspectJ Development Environment Guide](https://www.eclipse.org/aspectj/doc/next/devguide/printable.html)
  9. for more details about on-board AspectJ tools, such as _ajc_ (compiler), _ajdoc_ (aspect-enriched Javadoc), _aj_
  10. (load-time weaving helper), AspectJ Browser (simple visualisation tool for cross-cutting aspect structure) as well as
  11. basic information about load-time weaving configuration and the built-in Ant task for AspectJ.
  12. ## IDE support
  13. We are going to focus on the two IDEs the author of this document is acquainted with, Eclipse and IntelliJ IDEA. That
  14. does not mean that others such as NetBeans or the increasingly popular editor-on-steroids Visual Studio Code might not
  15. also be excellent choices, but I simply do not know them, sorry.
  16. ### Eclipse
  17. If you install [AspectJ Development Tools (AJDT)](https://www.eclipse.org/ajdt/), you can use AspectJ in the Eclipse
  18. Java IDE. For the last few years, AJDT has rather been kept alive than actively developed, but still it works nicely for
  19. the usual tasks, such as writing aspects in both native and annotation-style syntax, viewing cross-references between
  20. aspects and Java code, applying all sorts of weaving strategies (compile-time weaving, post-compile binary weaving,
  21. load-time weaving) and with an additional m2e (Maven to Eclipse) connector also for importing and refreshing from
  22. projects using AspectJ Maven Plugin.
  23. #### AspectJ Development Tools (AJDT)
  24. Use an update sites corresponding to your Eclipse version (minimal version listed):
  25. * Eclipse 2021-03 (4.19): https://aspectj.dev/eclipse/ajdt/419
  26. * Eclipse 2018-12 (4.10): https://download.eclipse.org/tools/ajdt/410/dev/update
  27. * For older versions, please refer to https://www.eclipse.org/ajdt/downloads (page was not updated in a long time,
  28. and I have no write access).
  29. #### Maven to Eclipse (m2e) connector
  30. The connector between AspectJ Maven Plugin and AJDT has not been maintained by the AspectJ team for some years, but
  31. there is a fairly up-to-date [fork by Miika Vesti (joker1)](https://github.com/joker1/m2eclipse-ajdt) with the following
  32. update sites:
  33. * Eclipse 2020-12 (4.18): https://repo.t5.fi/public/eclipse/m2eclipse-ajdt/eclipse-2020-12/
  34. * Eclipse 2019-06 (4.12): https://repo.t5.fi/public/eclipse/m2eclipse-ajdt/eclipse-2019-06/
  35. ### IntelliJ IDEA
  36. IDEA is a commercial IDE by JetBrains, which also has a free Community Edition. The author of this guide uses a
  37. complementary Ultimate Edition provided by JetBrains (thank you!), because he is an active open source developer (ask
  38. them if you are eligible, too). If you want to use the Ultimate Edition for commercial purposes, however, of course you
  39. need to buy it. According to [this resource](https://www.jetbrains.com/help/idea/aspectj.html), the AspectJ plugin is
  40. for the Ultimate Edition only, so probably the plugin is not going to work in the Community Edition. But if you are
  41. using AspectJ in your daytime job, probably you use the Ultimate Edition anyway.
  42. Make sure that the following plugins are active:
  43. * AOP Pointcut Language (bundled): basic AspectJ and Spring AOP pointcut syntax support (annotation style)
  44. * AspectJ (marketplace, author JetBrains): native AspectJ support
  45. If the Maven support bundled into IntelliJ IDEA is active as well, Maven projects using the AspectJ Maven Plugin will
  46. also be imported correctly. I never tested with any of the Gradle plugins or the AspectJ Ant task because I am a Maven
  47. user, so please try for yourself if those combinations are supported.
  48. ## Build tools
  49. ### Maven
  50. If you want to build your AspectJ projects with Maven, use [AspectJ Maven Plugin](https://github.com/dev-aspectj/aspectj-maven-plugin)
  51. by AspectJ.dev, artifact ID `dev.aspectj:aspectj-maven-plugin`. It is a fork of the original plugin by MojoHaus, which
  52. was inactive for 3.5 years and only recently (2021-07-30) had a new release. Because the AspectJ.dev version (maintained
  53. by AspectJ contributor Alexander Kriegisch) has more features, we recommend using it instead of the original for
  54. original's sake.
  55. ### Gradle
  56. In contrast to Maven, there is no de-facto standard build plugin for Gradle, but a bunch of more or less well-maintained
  57. plugins with a more or less complete feature set. I am not a Gradle user, but when answering related questions on
  58. StackOverflow, I got the impression that [Freefair by Lars Grefer](https://docs.freefair.io/gradle-plugins/current/reference/)
  59. is the one I want to recomment because of its good documentation, active development and feature set. It could well be
  60. or become for the Gradle ecosystem what AspectJ Maven is for the Maven one. At the time of writing this, the most recent
  61. milestone is [6.1.0-m3](https://docs.freefair.io/gradle-plugins/6.1.0-m3/reference/).
  62. ### Ant
  63. As mentioned in the introduction, AspectJ features its own Ant task, which is described in
  64. [this chapter](https://www.eclipse.org/aspectj/doc/next/devguide/printable.html#antTasks) of the Development Environment
  65. Guide.
  66. ## Biased recommendation
  67. Feel free to be skeptical, because the author has both IDE and build tool biases, but I am recommending Maven as a build
  68. tool, AspectJ Maven as a build plugin and then either of Eclipse or IDEA as integrated development environments (IDEs).
  69. Why? Because Maven + (Eclipse or IDEA) probably has the most complete tooling and best end-to-end user experience for
  70. AspectJ developers. Because I am also by far the most active AspectJ and Spring AOP supporter on StackOverflow, you also
  71. have better chances to receive spot-on answers than if e.g. you ask why your Ant or Gradle build does not work so nicely
  72. in NetBeans or VS Code. But by all means, please do choose whichever combination of tools is the prescribed standard in
  73. your work environment or simply your personal pereference. I believe that diversity is good. 🙂