Adding AspectJ to pom.xml changed Java version with Maven, why?

寵の児 提交于 2019-11-28 09:48:22

I think the problem is with the default source, target and complianceLevel settings of the aspectj-maven-plugin (according to the documentation linked previously, 1.4, 1.2 and 1.4 respectively). You should set these explicitly in your parent pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.5</version>
            <!-- new configuration is here -->
            <configuration>
                <complianceLevel>1.6</complianceLevel>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
<build>

I was missing

<complianceLevel>${java.level}</complianceLevel>

in my pom.xml

If you don't have define the version, the compiler plugin assumes that your Java source conforms to Java 1.3 and that you are targeting a Java 1.1 JVM.

Maybe, you should define it:

http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

egemen

You can find last versions of dependecy and plugin for aspectj.

I was missing the java version with jdk version at the top of my pom properties.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.2</version> <!-- 1.5 dint work for me -->
    <dependencies>
        <!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>process-sources</phase> <!-- or any phase before compile -->
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <outxml>true</outxml>
        <source>${jdk.version}</source>  <!-- I was missing this -->
        <target>${jdk.version}</target>  <!-- jdk.version property -->
    </configuration>
</plugin>

and at the top of my pom.xml I had set jdk.version property like,

<properties>
    <jdk.version>1.7</jdk.version>
</properties>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!