4

我正在尝试在我的日志记录层中使用一些漂亮的惰性日志记录技巧,但 AspectJ 对此感到窒息。我在 log4j 前面有一个门面。这是代码:

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

错误:

[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 );

这是我的 pom 位:

<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>

和:

        <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>

其他有趣的事实是,这在 Eclipse 中编译得很好,但是mvn package从 Linux 命令行运行时出现此错误。

经过进一步的试验/错误,我们发现如果我们手动设置JAVA_HOME为指向 Java 8,那么它可以编译。看起来 AspectJ 要求您JAVA_HOME指向正确的 Java 版本。在主 pom 中,我们指示 maven 使用特定版本的 Java:

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

这些似乎都不适用于 aspectj-maven-plugin 配置。

4

0 回答 0