Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Problems with test aspects in Eclipse

Hi Eric.

I cannot reproduce your problem. I have just given it a quick try with the attached sample project. It contains
  - a Maven build,
  - a corresponding IntelliJ IDEA 14 Maven project,
  - a corresponding Eclipse Luna SR1 (4.4.1) project, imported from Maven.

Both in IDEA and Eclipse the result is the same with Maven 3: The test aspect only applies to the sample JUnit test, *not* to the main class. When running the main class from either IDE, the aspect is not applied.

Maybe you have made a mistake setting up your Eclipse project. I recommend you to import your Maven build into a fresh Eclipse project. I also recommend to use a recent Maven AspectJ Plugin (1.7 instead of 1.2) and a recent AspectJ version (1.8.6, not 1.7.0, or at least 
the latest 1.7 versiobn 1.7.4).

Feel free to ask follow-up questions.

Regards
-- 
Alexander Kriegisch
http://scrum-master.de


Eric B schrieb am 18.06.2015 20:25:

> I posted a question on StackOverflow, but haven't received much traction there, so I thought I would check with people on this list as well.
> 
> 
> I'm having trouble with Eclipse weaving aspects from my test folder into my target/classes folder (as opposed to putting the woven classes into target/test-classes)
> 
> 
> I've got a maven project in which I have @Aspect classes in my src/test/java folder.  If I build from command line, everything runs properly.  If however, I build from within Eclipse, the compiler weaves my aspects into my target class files and puts them in target/classes.
> 
> 
> This obviously causes me troubles as the JVM tries to find the woven Aspect and throws NoClassDefFoundError (since the actual aspect.class is only in target/test-classes).
> 
> 
> Has anyone encountered this before?  Is there a way to instruct ajc/Eclipse/maven/m2e to put the woven class file into target/test-classes and not target/classes when it is due to an aspect from the test folder?
> 
> 
> My pom defn shows the following for the ajc plugin:
> 
> 
>       <plugin>
> 
>         <groupId>org.codehaus.mojo</groupId>
> 
>         <artifactId>aspectj-maven-plugin</artifactId>
> 
>         <version>1.2</version>
> 
>         <executions>
> 
>           <execution>
> 
>             <goals>
> 
>               <goal>compile</goal>
> 
>               <goal>test-compile</goal>
> 
>             </goals>
> 
>             <configuration>
> 
>               <outxml>true</outxml>
> 
>               <aspectLibraries>
> 
>                 <aspectLibrary>
> 
>                   <groupId>org.springframework</groupId>
> 
>                   <artifactId>spring-aspects</artifactId>
> 
>                 </aspectLibrary>
> 
>               </aspectLibraries>
> 
>               <source>7</source>
> 
>               <target>7</target>
> 
>             </configuration>
> 
>           </execution>
> 
>         </executions>
> 
>         <dependencies>
> 
>           <dependency>
> 
>             <groupId>org.aspectj</groupId>
> 
>             <artifactId>aspectjrt</artifactId>
> 
>             <version>1.7.0</version>
> 
>             <scope>compile</scope>
> 
>           </dependency>
> 
>           <dependency>
> 
>             <groupId>org.aspectj</groupId>
> 
>             <artifactId>aspectjtools</artifactId>
> 
>             <version>1.7.0</version>
> 
>             <scope>compile</scope>
> 
>           </dependency>
> 
>         </dependencies>
> 
>         <configuration>
> 
>           <outxml>true</outxml>
> 
>           <aspectLibraries>
> 
>             <aspectLibrary>
> 
>               <groupId>org.springframework</groupId>
> 
>               <artifactId>spring-aspects</artifactId>
> 
>             </aspectLibrary>
> 
>           </aspectLibraries>
> 
>           <source>7</source>
> 
>           <target>7</target>
> 
>         </configuration>
> 
>       </plugin>
> 
> 
> I've tried running maven 3.0.4 and 3.2.5, but no difference.
> 
> 
> Thanks,
> 
> Eric
> 
>

Attachment: SO_AJ_UnitTestSpecificAspect.zip
Description: Zip archive


Back to the top