我有一个在Scala中制作的域和一些用Java制作的类。我需要用Aspectj做一些方面的知识,因为使用Java类,它可以工作。 问题是,当Scala类注释它不起作用。其他注释(如hibernate的)和我的Scala类一起工作良好。使aspectj与scala模型一起工作
这是我的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Group</groupId>
<artifactId>Parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.source-target.version>1.8</java.source-target.version>
<aspectj.version>1.8.2</aspectj.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>createClassesDir</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}\unwoven-classes" />
<mkdir dir="${project.build.directory}\classes" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>${aspectj.version>}</source>
<target>${aspectj.version>}</target>
<weaveDirectories>
<weaveDirectory>${project.build.directory}\unwoven-classes</weaveDirectory>
</weaveDirectories>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>Aspects</module>
</modules>
</project>
我认为我必须做与Maven一些,因为方面和其他代码工作正常。 有没有办法做到这一点?
谢谢!
非常感谢!这个解决方案对于我上传的项目来说非常完美,我已经接受了pull请求,并对它进行了一些修改,使其成为多模块。感谢您的耐心和帮助! – Motomine
我刚刚发布了我的最后一个问题[here](http://stackoverflow.com/questions/43422025/using-aspectj-when-i-run-the-application-with-tomcat),请你帮我一下如果可能的话?谢谢! – Motomine
对于所有谁可能读这篇文章的人:@ Motomine的多模块的设置被打破,测试所有的IntelliJ IDEA在Maven和我失败了也。如果在我的[fork](https://github.com/kriegaex/aspectj-with-scala)中修复了它,并且还发出了另一个拉取请求。因此,如果有人正在寻找一个支持Scala的AspectJ多模块设置的展示,那么您可以在那里找到它。 – kriegaex