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

Thanks - I came to the same conclusion, but figured that I must have been doing something wrong.  I guess I have to raise this bug on the github project for AJDT and see if something can be done there.

Thanks,

Eric

On Sun, Jun 21, 2015 at 7:06 AM, Alexander Kriegisch <alexander@xxxxxxxxxxxxxx> wrote:
Hi Eric.

Please find my answer at http://stackoverflow.com/a/30954233/1082681. Basically I have added a default M2E lifecycle mapping for AspectJ Maven Plugin and now it works.

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


Eric B schrieb am 20.06.2015 21:43:
>
> Hi Alexander,
>
>
> Thanks for replying. I have since done additional testing/validation with
> Eclipse Luna but no additional success.
>
>
> I'm running into a problematic issue with m2e and Eclipse (vs command line
> maven build). I am using a clean installation of Luna WTP 4.4.2 with m2e
> 1.5.1.
>
>
> I have aspectj-maven-plugin configured in my pom.xml and the connector
> installed as well.
>
>
> My plugin configuration specifies:
>
>
> <executions>
>
> <execution>
>
> <id>compile</id>
>
> <goals>
>
> <goal>compile</goal>
>
> </goals>
>
> <configuration>
>
> <sources>
>
> <source>
>
> <basedir>${project.build.sourceDirectory}</basedir>
>
> </source>
>
> </sources>
>
> </configuration>
>
> </execution>
>
> <execution>
>
> <id>test compile</id>
>
> <goals>
>
> <goal>test-compile</goal>
>
> </goals>
>
> <configuration>
>
> <sources>
>
> <source>
>
> <basedir>${project.build.testSourceDirectory}</basedir>
>
> </source>
>
> </sources>
>
> <weaveDirectories>
>
> <param>${project.build.outputDirectory}</param>
>
> </weaveDirectories>
>
> </configuration>
>
> </execution>
>
> </executions>
>
>
> The goal is to have an aspect from my src/test/java path woven into my
> classes from src/main/java but output only in my target/test-classes. The
> reasoning behind this is that the aspect is only used for junit testing
> and not for normal code compilation/use.
>
>
> When I build from the command line, everything works properly. The
> "compile" goal compiles & weaves all my src/main/java files to the
> target/classes output directory and the "test-compile" compiles & weaves
> all my src/test/java files into target/test-classes.
>
>
> However, when I build from within Eclipse, my Aspects in src/test/java are
> woven into classes in target/classes as well (see
> target/classes/com/test/ServiceImpl.c
> <https://github.com/benze/aspectj-maven-plugin-defect-example/blob/master/src/main/java/com/test/ServiceImpl.java>
> lass. With the decompiler, I can see the MangleAspect has been woven in.
> Additionally, only the files from src/test/java are output into
> target/test-classes while the pom instructs ajc to do otherwise (weave all
> class files from target/classes into target/test-classes).
>
>
> I've enabled debug from cmd line when I build (mvn -X) and I can see
> appropriate parameters passed to the aspectj-maven-plugin. However when I
> enable debug logging from
> .metadata/.plugins/org.eclipse.m2e.logback.configuration/logback.${m2e.version}.xml,
> I do not see the parameters that are being passed to the
> aspectj-maven-plugin.
>
>
> Does this have something to do with the lifecycle mapping connector? Is
> there a way to debug how that is working?
>
>
> I uploaded my sample project to my github:
>
> https://github.com/benze/aspectj-maven-plugin-defect-example
>
>
> I did notice, however, if I disable the m2e connector and just use
> lifecycle mapping within my pom directly that instructs the aspectj plugin
> to execute on compile/test-compile goals, my output seems to be as I would
> expect. Can this be an m2e connector issue? I'm not entirely clear on how
> this connector works, or how it is injected into the m2e maven compile
> process.
>
>
> Thanks,
>
> Eric
>
>
> On Sat, Jun 20, 2015 at 7:53 AM, Alexander Kriegisch
> <alexander@xxxxxxxxxxxxxx <mailto:alexander@xxxxxxxxxxxxxx>
> > wrote:
>> 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
>> >
>> >
>>
>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> <mailto:aspectj-users@xxxxxxxxxxx>
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top