【发布时间】:2019-05-19 18:13:51
【问题描述】:
我有一个项目,它不是 Spring 应用程序。我正在尝试在其中使用 AspectJ 注释。 Annotation 类是从我拥有的另一个 jar 中引用的。我在下面提到了我的 POM 插件部分。我的构建成功,但 Maven 的控制台输出从未提及有关 AspectJ 插件的任何内容,而且当我运行我的项目时,注释也不起作用。
几个小时以来我一直试图找出问题所在,但无法弄清楚。
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>it.cvc.ciscocommerce.lps.lp-commons</groupId>
<artifactId>lp-commons</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>listpriceservice</warName>
</configuration>
</plugin>
<!-- Plugin for sdaas deployment. For compressing war to tar.gz -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
这是我试图用作方面库的 Jar 中定义的两个依赖项。
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.7.4</version>
</dependency>
jar 编译得很好,我打算在另一个 SPRING 应用程序中使用它,但不是这个。在 SPRING 应用程序中,我什至没有定义 maven aspect 插件。
当我运行 maven 构建时,在控制台中我只看到列出的以下插件。
[DEBUG] 目标:org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) [DEBUG] 样式:常规
[DEBUG] 目标:org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) [DEBUG] 样式:常规
[DEBUG] 目标:org.apache.maven.plugins:maven-resources-plugin:2.6:testResources (default-testResources) [DEBUG] 样式:常规
[DEBUG] 目标:org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) [DEBUG] 样式:常规
[DEBUG] 目标:org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) [DEBUG] 样式:常规
[DEBUG] 目标:org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) [DEBUG] 样式:常规
编辑:在阅读了 kriegaex 的回答以及关于 pluginManagement vs plugins 的内容后,我将我的 POM 更改如下。请注意,我的项目不是多模块的,它只有一个 POM。
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>it.cvc.ciscocommerce.lps.lp-commons</groupId>
<artifactId>lp-commons</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>listpriceservice</warName>
</configuration>
</plugin>
<!-- Plugin for sdaas deployment. For compressing war to tar.gz -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
当我这样做时,我在 AspectJ 执行下的执行标记上收到以下错误
生命周期配置未涵盖插件执行:org.codehaus.mojo:aspectj-maven-plugin:1.4:compile (execution: default, phase: process-sources)
更新我将此问题标记为已回答,因为我最初的 AspectJ 插件未被调用的问题已解决。我将就我的另一个问题提出一个新问题。感谢 kriegaex 为我指明了正确的方向。
【问题讨论】:
标签: eclipse maven build aspectj aspectj-maven-plugin