Aspectj-Maven-plugin,声明软如何编译 [英] aspectj-maven-plugin, declare soft how to compile
问题描述
是否可以仅使用aspectj-maven-plugin来编译具有软化异常(例如:declare soft: Exception : execution(* *.*());
)方面的项目?我无法处理...我仍然遇到编译错误
Is it possible to compile project with softened Exceptions (e.g.: declare soft: Exception : execution(* *.*());
) aspects in it using only aspectj-maven-plugin ? I can't handle it... I am still getting compilation error
unreported exception Exception; must be caught or declared to be thrown
因此,它在编译时没有考虑到任何方面.
So it is compiled without taking aspects in account.
我正在使用以下命令进行编译:
I am using this command to compile:
mvn clean aspectj:compile
我的pom.xml是:
and my pom.xml is:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>pl.group.id</groupId>
<artifactId>aop</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
<source>1.7</source>
<target>1.7</target>
<aspectDirectory>src/main/aspect</aspectDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我做错了什么?
推荐答案
实际上,我认为Maven Compiler Plugin 3.0和3.1中存在错误,因为它对我而言适用于插件版本2.5.1.自从3.1引入以来,增量编译似乎已中断或相应的开关useIncrementalCompilation
在某种意义上被意外颠倒了.有趣的是,将其值设置为false
可以解决我的问题.降级到2.5.1也可以.在这两种情况下,我都需要按照用户@Gus链接的问题中所述,将AspectJ Maven插件的阶段更改为process-sources
.
Actually I think there is a bug in Maven Compiler Plugin 3.0 and 3.1 because for me it works with plugin version 2.5.1. It seems that incremental compilation is broken or the corresponding switch useIncrementalCompilation
is somehow accidentally reversed in its meaning since it was introduced in 3.1. Funnily, setting its value to false
fixes the situation for me. Downgrading to 2.5.1 also does. In both cases I need to change the phase for the AspectJ Maven Plugin to process-sources
as described in the question linked to by user @Gus.
解决方案A:
<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>de.scrum-master.stackoverflow</groupId>
<artifactId>aspectj-soft-exceptions</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.8.0</aspectj.version>
</properties>
<name>AspectJ sample with declare soft</name>
<description>Demonstrates how to build an AspectJ project using "declare soft" with Maven</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.7</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
解决方案B:
<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>de.scrum-master.stackoverflow</groupId>
<artifactId>aspectj-soft-exceptions</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.8.0</aspectj.version>
</properties>
<name>AspectJ sample with declare soft</name>
<description>Demonstrates how to build an AspectJ project using "declare soft" with Maven</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- IMPORTANT - or remove this plugin config altogether because 2.5.1 is the default in Maven 3 anyway -->
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.7</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
这篇关于Aspectj-Maven-plugin,声明软如何编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!