在Maven项目中使用AspectJ:编织不起作用

我正在尝试在Using AspectJ annotations in maven project: weaving is not working中使用此处给出的答案重现示例。在关节方面,现在我正在使用eclipse Photon,JDK 1.8,但没有成功。

我的最终POM.XML是:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>aspect-tutorial</artifactId>
<version>0.0.1-snAPSHOT</version>
<properties>
    <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.9.5</version>
    </dependency>
</dependencies>

<build>
    <pluginmanagement>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11</version>
                <configuration>
                    <complianceLevel>1.8</complianceLevel>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <!-- IMPORTANT -->
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <!-- IMPORTANT -->
                    <useIncrementalCompilation>false</useIncrementalCompilation>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <mainClass>com.pkg.MainApp</mainClass>
                </configuration>
            </plugin>

        </plugins>
    </pluginmanagement>
</build></project>

我已经尝试同时使用eclipse(MainApp->运行方式...)和Maven(pom.xml->运行方式-> Maven Build)运行,但是没有进行任何编织。有想法吗?

非常感谢!比阿

sdl2874 回答:在Maven项目中使用AspectJ:编织不起作用

forked your repo并修复了您的Maven POM。您实际上是通过在if submitpageform.validate_on_submit(): for w in whiskies: w.is_whiskey = is_whiskey_form.is_whiskey.data db.session.commit() 部分中预先配置插件而犯了Maven初学者的错误,但实际上并未在 public ArrayList<PlayListModel> getPlaylist(String playlistName) { SQLiteDatabase db = this.getReadableDatabase(); ArrayList<PlayListModel> obj = new ArrayList<PlayListModel>(); Cursor cursor = db.query(TABLE_PLAYLIST,new String[] { KEY_ID,KEY_TITLE,KEY_SINGER,KEY_PATH,KEY_PLAYLISTNAME,KEY_DUR },KEY_PLAYLISTNAME+ "=?",new String[] { playlistName },null,null); if (cursor != null) cursor.moveToFirst(); PlayListModel contact = new PlayListModel (cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4),cursor.getString(5)); obj.add(contact); // return contact return obj; } 部分中声明使用预先配置的插件。在那种情况下,Maven当然不会使用AspectJ Maven插件,因此不会编织任何方面。

我给您发送了一个pull request,您可以接受以使其生效。您的Maven设置中还有其他几处可以改进的地方,例如

  • 如果您确实要使用AspectJ 1.9.5,而不是AspectJ Maven中使用的预先配置的1.8.13,则有一种方法可以实现,但不是您使用的方法。如果这是一个问题,请随时询问更多详细信息。

  • 如果要使用8以上的JDK来运行Maven构建。在这种情况下,您需要切换到AspectJ Maven的分支,因为1.11版不适用于JDK 9+。如有必要,我也可以在此提供更多详细信息。但是使用JDK 8,您应该没事。

本文链接:https://www.f2er.com/2837407.html

大家都在问