1

I've written a maven module which uses AspectJ, and I'm compiling it with the AspectJ compiler plugin. I've written some unit tests which use Java 8 predicates, and when I run mvn clean install, the tests fail with this error:

error: lambda expressions are not supported in -source 1.5

Weirdly, when I include the standard compiler plugin as well as the aspectj compiler, it builds without issue. I'm reluctant to use both plugins since I believe they should be mutually exclusive?

compiler is setup as follows:

 <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.8</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>
    </plugins>
</build>
TheRealJimShady
  • 3,815
  • 4
  • 21
  • 40

1 Answers1

0

The error you are getting is from maven compiler, it has to have source level configured:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • ...so how does it work? I thought you would either have the standard maven compiler (as you've described) OR the aspectj compiler? – TheRealJimShady Jun 26 '16 at 20:31
  • aspectj is running after the java compiler and it does bytecode weaving on existing .class files – Krzysztof Krasoń Jun 27 '16 at 05:04
  • ...even using compile-time weaving? – TheRealJimShady Jun 27 '16 at 07:53
  • 1
    If you like you can use the AspectJ compiler as a drop-in replacement for the standard Java compiler because _Ajc_ is an extended version of the Eclipse compiler and thus compiles normal Java classes as well, not just aspects. If you wish to do this, just deactivate the Maven Compiler plugin for the Maven module in question. – kriegaex Jul 02 '16 at 09:03