Running JDK8 for aspectj

后端 未结 3 966
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 22:25

I am trying to run aspectj-maven plugin with JDK8. But it is giving errors like \"The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from requir

相关标签:
3条回答
  • 2021-01-04 22:45

    You don't need 1.7-SNAPSHOT for that. I have this snippent in POM and everything works:

    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>aspectj-maven-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <complianceLevel>1.8</complianceLevel>
                            <showWeaveInfo>true</showWeaveInfo>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.aspectj</groupId>
                                <artifactId>aspectjrt</artifactId>
                                <version>1.8.1</version>
                            </dependency>
                            <dependency>
                                <groupId>org.aspectj</groupId>
                                <artifactId>aspectjtools</artifactId>
                                <version>1.8.1</version>
                            </dependency>
                        </dependencies>
    
                    </plugin>
    
    0 讨论(0)
  • 2021-01-04 23:04

    I had to achieve the same and I drove crazy trying to figure out this, fortunately I could solve it and here I give you what I did:

    To use aspectj-maven-plugin with Java 8 you need version aspectj-maven-plugin 1.7 (Note that aspectj-maven-plugin 1.6 works for Java 7).

    So, the maven plugin configuration needs to be:

            <!-- AspectJ configuration -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.7-SNAPSHOT</version>
                <configuration>
                    <complianceLevel>1.8</complianceLevel>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    By the way, the aspectJ jars needed are:

        <!-- Spring AOP + AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.1</version>
        </dependency>
    

    And the most important thing I've struggled was that you need to install the aspectj-maven-plugin 1.7 jar manually into your pom.xml since this jar aren't on maven repo yet.

    You can get it from Haus Jira (look at the Attachment section):

    https://jira.codehaus.org/browse/MASPECTJ-131
    

    Btw, once you download it an copy it to your repo you need to create your own aspectj-maven-plugin-1.7-SNAPSHOT.pom file within the corresponding directory. You can copy it from version 1.6 BUT ensure you modify the following content:

     <version>1.7-SNAPSHOT</version>
    
     <properties>
        <aspectjVersion>1.8.1</aspectjVersion>
        <mavenVersion>2.2.1</mavenVersion>
        <changesPluginVersion>2.9</changesPluginVersion>
     </properties>
    

    That's all here you go, hope to help.

    0 讨论(0)
  • 2021-01-04 23:09

    Another way to solve this problem is to downgrade JDK level to 1.7. JDK 1.7 works well with aspectj-maven-plugin of versions 1.4 - 1.6.

    Here is a screenshot showing how to change JDK level in IntelliJ IDEA project:

    Set Project SDK to 1.7. See documentation for more details.

    0 讨论(0)
提交回复
热议问题