0

colleagues.

I connect aspects, native ajc compiler. Idea used: Intelleje IDEA

Technologies on the project:

Maven
Spring boot
Lombok

Problem: Trying to run aspectj for java 16 with integrated stack of the above technologies. + framework for automating the assembly of projects to build in jar with working aspects

I tried:

1. plugin for automated project building "org.codehaus.mojo" works only with Java 1.8, I cannot use later versions. As I understand it, the plugin is outdated.

2. Including aspectjrt in project dependencies and assigning aspectjtools and aspectjweawer to the project facet

3. Various manipulations with installing the Java version in ide

Results:

1. Works but target is not achieved (java before 8)
2. Does not work
3. Does not work

Spent time studying the material: 2-3 weeks, shoveled a bunch of articles and Internet resources. Also read the book casually AspectJ in action

I am attaching a pom file with a working plugin:

         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>MyAopWithoutSpring</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--    <parent>-->
    <!--        <groupId>com.baeldung</groupId>-->
    <!--        <artifactId>parent-boot-2</artifactId>-->
    <!--        <version>0.0.1-SNAPSHOT</version>-->
    <!--        <relativePath>../parent-boot-2</relativePath>-->
    <!--    </parent>-->
    <!--    <parent>-->
    <!--        -->
    <!--    </parent>-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>${aspectj-plugin.version}</version>
                <configuration>
                    <complianceLevel>${java.version}</complianceLevel>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <Xlint>ignore</Xlint>
                    <encoding>UTF-8</encoding>
                    <excludes>
                        <exclude>**/pointcutadvice/**</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>10</source>
                    <target>10</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <aspectj-plugin.version>1.11</aspectj-plugin.version>
        <java.version>1.8</java.version>
    </properties>

</project> ```

To be honest, I am already ready to despair, I do not understand the sequence of actions at all in order for it to somehow work on the technology stack that is necessary. I will be glad to any advice and tips from more experienced colleagues
Eduard
  • 1
  • 1
  • Welcome to SO. Please learn how to ask good questions here by always presenting a reproducible code sample, ideally an [MCVE](https://stackoverflow.com/help/mcve) - please do read the article! Please also note that you should ask one clear question and not list several issues without asking anything in particular. I tried to answer your question(s) this time, it was your free shot. Next time, probably someone is going to close a question like this. – kriegaex Oct 14 '21 at 08:40
  • Feedback, please. Don't just ask questions but then not react to answers or comment, which is not very polite. Thank you. – kriegaex Oct 28 '21 at 12:11

1 Answers1

0
  • Version 1.14.0 of the MojoHaus AspectJ Maven Plugin supports Java 16.
  • Version 1.13.1 of the AspectJ.dev AspectJ Maven Plugin has additional features, supports Java 16 and 17 and can be configured to support future Java and AspectJ versions greater than 17 too.
  • Both plugins already have a dependency on the AspectJ compiler contained in aspectjtools, which you can up- or downgrade, if you need a specific version.
  • You do need to add aspectjrt when using compile-time weaving, because running AspectJ-enabled programs needs a small AspectJ runtime.
  • IntelliJ IDEA has plugins for "AspectJ" (marketplace, author JetBrains) and "AOP Pointcut Language" (bundled). You can install both in order to get support for the AspectJ syntax and also for AspectJ Maven Plugin (both variants mentioned above).
  • When combining Lombok and AspectJ, please be aware of possible problems, because they both fork the Eclipse Java Compiler in different ways. The problems can be solved by either weaving delomboked source code or by first applying Lombok with javac and then adding an additional AspectJ binary weaving build step. See here and here
kriegaex
  • 63,017
  • 15
  • 111
  • 202