Aspectj compilation works in maven, fails in intellij

Answered

When building the project in maven, the aspects got woven correctly - but in intellij they fail with the following warnings like:

 

Warning:ajc: this affected type is not exposed to the weaver: ...User [Xlint:typeNotExposedToWeaver]

Warning:ajc: advice defined in ...SecurityAspect has not been applied [Xlint:adviceDidNotMatch]

 

It fails on both complete project rebuild and per-file recompilations.

 

* File > Preferences > Build > Compiler > Use compiler is set to ajc and the path to ajc compiler works (validated with test button).

* Un-applied aspects are in .aj form and part of the current project.

Relevant plugins in maven POM:

 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<complianceLevel>${java.version}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-web-resources</directory>
</resource>
</webResources>
</configuration>
</plugin>

 

Am I missing something?

 

0
7 comments

Please report at https://youtrack.jetbrains.com/issues/IDEA with the sample project to reproduce attached. Thanks!

0
Avatar
Permanently deleted user

Serge, I am trying to create a sample event where I can reproduce this but it is easier said than done. Apparently there is some combination of things in my project that is causing this. Something is causing some classes not to be included in the ajc compilation (I have disabled propagation to javac). Is there any way I can find out more why, using some debug log or something?

0
Avatar
Permanently deleted user

It appears that the project-aspects are weaved in when rebuilding the whole project, but not when recompiling a single file. I checked the byte code:

 

Not working:

@Trusted
@Transactional
public void onApplicationEvent(ContextRefreshedEvent event) {
AnnotationTransactionAspect var10000 = AnnotationTransactionAspect.aspectOf();
Object[] var4 = new Object[]{this, event};
var10000.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(this, new ApplicationServiceImpl$AjcClosure1(var4), ajc$tjp_0);
}


Working:

@Trusted
@Transactional
public void onApplicationEvent(ContextRefreshedEvent event) {
JoinPoint var4 = Factory.makeJP(ajc$tjp_0, this, this, event);
AnnotationTransactionAspect var10000 = AnnotationTransactionAspect.aspectOf();
Object[] var6 = new Object[]{this, event, var4};
var10000.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(this, new AjcClosure3(var6), ajc$tjp_0);
}

 

As you can see the spring transaction aspects are weaved in in both cases but the local aspects are not. Is this a known issue and possible to do anything about?

0
Avatar
Permanently deleted user

Serge: yes it seems to be the same bug unfortunately. And sadly it seems like it´s not being worked on either?

0
Avatar
Permanently deleted user

The bug has been active in the bug tracker for around 3 years already. Is there any hope of it being adressed or should we aspectj users look for other options?

2

Please sign in to leave a comment.