且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在一个项目中使用Aspectj编译时编织和Java编译时注释处理

更新时间:2023-09-15 19:18:46

到目前为止,对我来说,***的策略是在使用AspectJ编译器时完全禁用Java编译器,并让AspectJ编译器单独进行注释处理和编译.一个示例maven构建配置如下所示:

For me the best strategy so far was to disable the Java compiler altogether when using the AspectJ compiler, and let the AspectJ compiler do the annotation processing and the compilation alone. An example maven build configuration would look like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <skipMain>true</skipMain>
                <skip>true</skip>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

如果由于某种原因对您不起作用,您可以尝试将Java编译器仅用于注释处理,然后让AspectJ编译器完成其余的工作.

If that doesn't work for you for some reason, you could try using the Java compiler for annotation processing only and let the AspectJ compiler do the rest.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <proc>only</proc>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <configuration>
                <proc>none</proc>
            </configuration>
        </plugin>
    </plugins>
</build>

我还看到您在构建文件中定义了太多执行(对于Java编译器为2个:default-compile + compile-project),具有非默认执行ID.我建议您只保留具有默认ID的默认执行,除非您有特定的原因要保留它们.

I also see you've got too many executions defined in your build file (2 for the java compiler: default-compile + compile-project), with non-default execution IDs. I suggest you leave only the default executions with their default ID, unless you have a specific reason for having them.