Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323963 - Installed AJDT causes .aj files to be compiled with the Java compiler for non-AspectJ projects
Summary: Installed AJDT causes .aj files to be compiled with the Java compiler for non...
Status: RESOLVED WONTFIX
Alias: None
Product: AJDT
Classification: Tools
Component: Core (show other bugs)
Version: 2.1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 2.1.1   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-30 09:05 EDT by Emond Papegaaij CLA
Modified: 2010-08-31 16:38 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emond Papegaaij CLA 2010-08-30 09:05:57 EDT
When a Java project (using the Java Builder) contains an AspectJ (.aj) file, and AJDT is installed, Eclipse tries to compile this file with the plain Java compiler, which fails.

In our project, we optionally enable AspectJ. This project contains an .aj file, which should only be used when AspectJ is enabled (and the project is build with the AJ-builder). However, on systems with AJDT installed, this file is also compiled for plain Java projects. This project does not have the AspectJ nature, nor does it use the AJ-builder.
Comment 1 Andrew Eisenberg CLA 2010-08-30 11:03:43 EDT
This is the expected behavior.  *.aj files are set up as "Java-like" files so that they can be handled similarly to Java files in places like the package explorer, outline view, search, etc.  However, the side-effect of this is that *.aj files will be sent to the java compiler by default.

The solution is to select all of your aspect files right-click -> Build Path -> Exclude.  

This will exclude all of your aj files from building.  If you add the AJ nature to your project, then all of these files will automatically be included again.  Removing them will automatically exclude them.

So, although the behavior is not exactly as you would like, there is a reasonable work around.
Comment 2 Emond Papegaaij CLA 2010-08-31 03:36:56 EDT
We generate the build path with the Maven Eclipse plugin, therefore it is not practical to manually edit the it; the next time you run mvn eclipse:eclipse, your change will be reverted. For some reason, it is not possible to use sourceExcludes in our pom. The problem is that the .aj files are also seen as 'Java-like' for projects without the AJ nature. Isn't it possible to only register them as 'Java-like' for projects with the AJ nature?
Comment 3 Andrew Eisenberg CLA 2010-08-31 11:59:51 EDT
Unfortunately, the answer is no.  JDT caches the java-like file extensions for the entire workspace after calculating them once.

Two possibilities:

1. Can you put your aspects in src/aspectj?  It's possible that mvn eclipse:eclipse will not generate an source folder for it and if it does, then it is easier to exclude a single folder than individual source files.

2. Have you considered m2eclipse?  It provides much better knowledge about AspectJ and may make things work better.
Comment 4 Emond Papegaaij CLA 2010-08-31 15:55:19 EDT
Ok, that's unfortunate. The first option seems like a good solution for now. I'll see if that will work for us. I think, I'll also file a bug report for the problems with the sourceExcludes for the maven-eclipse-plugin.

We've tried m2eclipse several times, and failed miserably. It just can't cope with large, multi-module projects with complex inheritance structures in the poms and different Maven profiles. We try it every now and then to see if there is any improvement, but it simply isn't up to the task for our project. Last time, it only took several hours of development until all dependencies of the project were broken beyond repair. Somehow all project dependencies got inverted and nothing helped to get them right again. Since then, our project only has become much more complex and little seems to have been done on m2eclipse. Perhaps we'll give it another try in a few months.
Comment 5 Andrew Eisenberg CLA 2010-08-31 16:38:44 EDT
Hmmmm...I suppose I could provide a command to automatically exclude all .aj files from a Java project.