4

I'm trying to use some nifty lazy logging tricks in my logging layer but AspectJ is choking on it. I have a facade in front of log4j. Here's the code:

public void debug ( Supplier<String> message )
{
    if( isDebugEnabled() )
    {
        debug( message.get() );
    }
}

The error:

[ERROR] The type java.util.function.Supplier cannot be resolved. It is indirectly referenced from required .class files
        /home/Build/src/Core/Database/src/com/BasicDao.java:1006
LOGGER.debug( "Retry number: "+retryCount+"DB Lock Conflict, sleeping "+retrySleepTime );

Here's my pom bits:

<plugin>
    <!-- This plugin integrates aspectj into our build cycle -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <complianceLevel>1.8</complianceLevel>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.8.5</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
         </execution>
    </executions>
</plugin>

And:

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.5</version>
        </dependency>

Other interesting facts are that this compiles fine within Eclipse, but I get this error when running mvn package from a Linux command line.

Upon further trial/error we have discovered that if we manually set JAVA_HOME to point to Java 8 then it compiles. It looks like AspectJ requires your JAVA_HOME to point to the right version of Java. In the main pom we are directing maven to use the specific version of Java with:

<executable>${JAVA_1_8_HOME}/bin/javac</executable>
<jvm>${JAVA_1_8_HOME}/jre/bin/java</jvm>

Neither of those seemed to work with the aspectj-maven-plugin configuration.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
darrickc
  • 1,872
  • 6
  • 27
  • 38

0 Answers0