Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Setting up an AspectJ development environment
  2. _by Alexander Kriegisch, originally published on 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, Mill 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](../devguide/index.adoc)
  9. for more details about on-board AspectJ tools, such as _ajc_ (compiler), _ajdoc_ (aspect-enriched Javadoc), _aj_
  10. (load-time weaving helper) as well as basic information about load-time weaving configuration and the built-in Ant task
  11. 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 site corresponding to your Eclipse version (minimal version listed):
  25. // AspectJ_JDK_Update: add new release to table
  26. * Eclipse 2024-03 (4.31), AspectJ 1.9.22, Java 22: https://download.eclipse.org/tools/aspectj/ajdt/431/dev/update
  27. * Eclipse 2023-12 (4.30), AspectJ 1.9.21, Java 21: https://download.eclipse.org/tools/aspectj/ajdt/430/dev/update<br>
  28. **Please note:** In Eclipse 2023-12, you should also add
  29. https://download.eclipse.org/eclipse/updates/4.31-I-builds/I20231201-1800/ in addition to the regular release update
  30. sites https://download.eclipse.org/eclipse/updates/4.30/ or https://download.eclipse.org/releases/latest. This is,
  31. because AspectJ 1.9.21 contains support for JDK 21 string templates, which was added to the compiler after the 2023-12
  32. release, but also includes a few Eclipse API changes requiring the additional update site. After adding it, please
  33. make sure to call _Help_ → _Check for Updates_ and accept the updates.
  34. * Eclipse 2022-12 (4.26), AspectJ 1.9.19, Java 19: https://download.eclipse.org/tools/aspectj/ajdt/426/dev/update
  35. * Eclipse 2022-03 (4.23), AspectJ 1.9.19, Java 19: https://download.eclipse.org/tools/aspectj/ajdt/423/dev/update
  36. * Eclipse 2021-09 (4.21), AspectJ 1.9.8, Java 17: https://download.eclipse.org/tools/aspectj/ajdt/421/dev/update
  37. * Eclipse 2021-03 (4.19), AspectJ 1.9.7, Java 16: https://download.eclipse.org/tools/aspectj/ajdt/419/dev/update
  38. * Eclipse 2018-12 (4.10), AspectJ 1.9.6, Java 14: https://download.eclipse.org/tools/aspectj/ajdt/410/dev/update
  39. * For older versions, please refer to https://www.eclipse.org/ajdt/downloads (page was not updated in a long time,
  40. and I have no write access).
  41. #### Maven to Eclipse (M2E) connector
  42. The M2E connector is capable of importing build settings from AspectJ Maven Plugin (see section "Build tools / Maven"
  43. below).
  44. As of April 2024, AspectJ developer Alexander Kriegisch published a [fork of the project](https://github.com/dev-aspectj/m2eclipse-ajdt)
  45. and corresponding Eclipse update sites here:
  46. * Eclipse 2024-03 (4.31): https://aspectj.dev/maven/m2eclipse-ajdt/eclipse-2024-03/
  47. * Eclipse 2022-12 (4.26): https://aspectj.dev/maven/m2eclipse-ajdt/eclipse-2022-12/
  48. * Eclipse 2020-12 (4.18): https://aspectj.dev/maven/m2eclipse-ajdt/eclipse-2020-12/
  49. * Eclipse 2019-06 (4.12): https://aspectj.dev/maven/m2eclipse-ajdt/eclipse-2019-06/
  50. The project is only maintained on a best-effort basis, and not each update published has a proper new release version.
  51. If your snapshot does not update properly (Eclipse failing to calculate solutions for installation and saying that the
  52. plugin is already installed), simply uninstall the "Maven Integration for AJDT (Optional)" feature from Eclipse,
  53. re-start the IDE and install again from the corresponding update site.
  54. History: The connector between AspectJ Maven Plugin and AJDT had not been maintained for some years, but until 2023
  55. there was a fairly up-to-date [fork by Miika Vesti (joker1)](https://github.com/joker1/m2eclipse-ajdt) with update sites on host **repo.t5.fi**, which are
  56. no longer available. Hence, the **aspectj.dev** ones listed above.
  57. #### Update sites example
  58. Your AspectJ-related list of Eclipse update sites for AJDT and the M2E connector could look like this for
  59. Eclipse 2023-12:
  60. ![Eclipse IDE filtered list of update sites](images/EclipseSoftwareSitesAJDT.png)
  61. ### IntelliJ IDEA
  62. IDEA is a commercial IDE by JetBrains, which also has a free Community Edition. The author of this guide uses a
  63. complementary Ultimate Edition provided by JetBrains (thank you!), because he is an active open source developer (ask
  64. them if you are eligible, too). If you want to use the Ultimate Edition for commercial purposes, however, of course you
  65. need to buy it. According to [this resource](https://www.jetbrains.com/help/idea/aspectj.html), the AspectJ plugin is
  66. for the Ultimate Edition only, so probably the plugin is not going to work in the Community Edition. But if you are
  67. using AspectJ in your daytime job, probably you use the Ultimate Edition anyway.
  68. Make sure that the following plugins are active:
  69. * AOP Pointcut Language (bundled): basic AspectJ and Spring AOP pointcut syntax support (annotation style)
  70. * AspectJ (marketplace, author JetBrains): native AspectJ support
  71. If the Maven support bundled into IntelliJ IDEA is active as well, Maven projects using the AspectJ Maven Plugin will
  72. also be imported correctly. I never tested with any of the Gradle plugins or the AspectJ Ant task because I am a Maven
  73. user, so please try for yourself if those combinations are supported.
  74. ## Build tools
  75. ### Maven
  76. If you want to build your AspectJ projects with Maven, use [AspectJ Maven Plugin](https://github.com/dev-aspectj/aspectj-maven-plugin)
  77. by AspectJ.dev, artifact ID `dev.aspectj:aspectj-maven-plugin`. It is a fork of the original plugin by MojoHaus, which
  78. was inactive for several years and even now shows no activity other than AspectJ version bumps. Because the AspectJ.dev
  79. version has more features and is actively maintained by Alexander Kriegisch from the AspectJ core team, we recommend
  80. using it instead of the Mojohaus version.
  81. ### Gradle
  82. In contrast to Maven, there is no de-facto standard build plugin for Gradle, but a bunch of more or less well-maintained
  83. plugins with a more or less complete feature set. I am not a Gradle user, but when answering related questions on
  84. Stack Overflow, I got the impression that [Freefair by Lars Grefer](https://docs.freefair.io/gradle-plugins/current/reference/#_aspectj_plugins)
  85. is the one I want to recommend because of its good documentation, active development and feature set. It could well be
  86. or become for the Gradle ecosystem what AspectJ Maven is for the Maven one. A few examples can be found
  87. [here](https://github.com/freefair/gradle-plugins/tree/main/examples/aspectj).
  88. ### Mill
  89. If you want to build your AspectJ projects with the [Mill Build Tool](https://github.com/com-lihaoyi/mill), you can use
  90. the [mill-aspectj](https://github.com/lefou/mill-aspectj) plugin. It is actively maintained, and its author Tobias
  91. Roeser is also the maintainer of Mill. It supports all important settings of AspectJ and is even providing convenience
  92. options for polyglot projects, e.g. it features an option for out-of-the-box chained compilation with Zinc (for
  93. Java/Scala) and AspectJ (for weaving aspects) in the same module.
  94. ### Ant
  95. As mentioned in the introduction, AspectJ features its own Ant task, which is described in
  96. [this chapter](../devguide/antsupport.adoc) of the Development Environment
  97. Guide.
  98. ### Command line
  99. If you wish to install AspectJ in a separate directory and use it from the command line without any extra build tools,
  100. feel free to download the **AspectJ installer**. It is an executable JAR installer, requires Java and possibly admin
  101. rights, if e.g. under Windows you want to install AspectJ to _C:/Program Files/AspectJ_. You execute it from a command
  102. prompt via `java -jar installer-<version>.jar` and select your installation options. Then you add `<ASPECTJ_HOME>/bin`
  103. to your path and are good to go. You can now call tools like the Aspectj compiler `ajc` or the AspectJ documentation
  104. generator `ajdoc` (similar to Javadoc) from the command line.
  105. You can find older installer versions until 1.9.6 on the [AspectJ website](https://www.eclipse.org/aspectj/downloads.php),
  106. more recent ones are attached to AspectJ [GitHub releases](https://github.com/eclipse-aspectj/aspectj/releases) as
  107. _aspectj-*jar_.
  108. ## Biased recommendation
  109. Feel free to be skeptical, because the author has both IDE and build tool biases, but I am recommending Maven as a build
  110. tool, AspectJ Maven as a build plugin and then either of Eclipse or IDEA as integrated development environments (IDEs).
  111. Why? Because Maven + (Eclipse or IDEA) probably has the most complete tooling and best end-to-end user experience for
  112. AspectJ developers. Because I am also by far the most active AspectJ and Spring AOP supporter on Stack Overflow, you also
  113. 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
  114. in NetBeans or VS Code. But by all means, please do choose whichever combination of tools is the prescribed standard in
  115. your work environment or simply your personal pereference. I believe, that diversity is good. 🙂