AspectJ Maven Plugin cannot compile my project
Asked Answered
F

5

21

I try to use aspectj maven plugin for compile project with aspectj compiler and then I try to package classes into "war" file. Unfortunately, it doesn't work with following configuration (pom.xml):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.liferay.maven.plugins</groupId>
            <artifactId>liferay-maven-plugin</artifactId>
            <version>${liferay.maven.plugin.version}</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <configuration>
                <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                <liferayVersion>${liferay.version}</liferayVersion>
                <pluginType>portlet</pluginType>

            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.7</source>
                <target>1.7</target>
                <showWarnings>true</showWarnings>
                <failOnError>true</failOnError>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.7</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilationLevel>1.7</compilationLevel>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.7.4</version>
    <type>jar</type>
</dependency>

After mvn clean install I see following exceptions:

[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ tvbs-portlet ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] Missing message: configure.incompatibleComplianceForSource in: org.aspectj.ajdt.ajc.messages
    <unknown source file>:<no line information>

[ERROR] no sources specified
    <unknown source file>:<no line information>

[ERROR] AspectJ Compiler 1.8.2

    Usage: <options> <source file | @argfile>..

AspectJ-specific options:
    -inpath <list>      use classes in dirs and jars/zips in <list> as source

Could anybody suggest me some solution?

Frig answered 11/11, 2014 at 11:5 Comment(1)
Would you mind accepting + upvoting my answer (the one with the screenshot)? I still think it is correct and just stumpled upon it again.Hermia
H
9

Update: While the things I said about AspectJ Maven configuration in this answer are all correct, the root cause of the concrete problem at hand - bad Maven dependency management - is described in my other answer. It would be better if that one was the accepted answer and not this one.


  • User codelion's hint makes sense, please change your <compilationLevel> tag (typo?) - to <complianceLevel>.
  • There is no need to downgrade to plugin version 1.6, you can keep 1.7.
  • There is also no need to specify the configuration again within the <execution> section, the one at plugin level is enough.
  • Please note that the default AspectJ version in plugin 1.7 is 1.8.2, so maybe your runtime dependency on 1.7.4 works, but if I were you I would upgrade that one too, optimally in sync with the plugin version. It is no hard requirement, but I think it makes sense.
  • Maybe you even want to upgrade to the current version AspectJ 1.8.4, in the plugin as well as the runtime. This can also be achieved by adding a dependency to the desired aspectjtools version to the plugin configuration:
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.source-target.version>1.8</java.source-target.version>
        <aspectj.version>1.8.4</aspectj.version>
    </properties>

    <build>
        <pluginManagement>
             <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.7</version>
                    <configuration>
                        <showWeaveInfo>true</showWeaveInfo>
                        <source>${java.source-target.version}</source>
                        <target>${java.source-target.version}</target>
                        <Xlint>ignore</Xlint>
                        <complianceLevel>${java.source-target.version}</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>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>${aspectj.version}</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
    </dependencies>
Hermia answered 11/11, 2014 at 14:8 Comment(4)
Thank you for answer. I tried to use your configuration, but still get previous result ("[ERROR] PESSIMISTIC_WRITE cannot be resolved or is not a field", "[ERROR] The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<Entitle>)" and other errors like this). Maybe aspectj compiler different from javac and has some problems with enums and etc.?Frig
Can you give me access to your project via GitHub or similar? I have done quite a few things with AJMaven plugin ans AJ itself, so maybe I can help you better when I see the actual code. We can also make a private arrangement if a public repo is not possible.Hermia
I forked your repo at github.com/kriegaex/test-aspectj, but even after removing the parent POM (which I do not have) and manually setting dummy values to liferay parameters, I cannot build because I have no access to your Maven repo at maven.elcom.spb.ru, probably because it is an internal repo. Besides, you have committed your Maven 'target' folder to Git, which you should not have done. I have removed it in my fork. Can you please provide me with a stand-alone project reproducing your problem? I do not even get as far as seeing the real problem.Hermia
I just noticed your last comment after having explained in my new answer why this works and what is really wrong.Hermia
G
17

It seems like a known issue http://jira.codehaus.org/browse/MASPECTJ-125

You can fix it by adding the following to your pom file.

<complianceLevel>1.6</complianceLevel>
Geomorphic answered 11/11, 2014 at 11:8 Comment(2)
Just tested this with compliance level 1.8 and I can verify that it did fix the bug for me.Buitenzorg
@RIng Same for java 11Pattypatulous
H
9

Update: While the things I said about AspectJ Maven configuration in this answer are all correct, the root cause of the concrete problem at hand - bad Maven dependency management - is described in my other answer. It would be better if that one was the accepted answer and not this one.


  • User codelion's hint makes sense, please change your <compilationLevel> tag (typo?) - to <complianceLevel>.
  • There is no need to downgrade to plugin version 1.6, you can keep 1.7.
  • There is also no need to specify the configuration again within the <execution> section, the one at plugin level is enough.
  • Please note that the default AspectJ version in plugin 1.7 is 1.8.2, so maybe your runtime dependency on 1.7.4 works, but if I were you I would upgrade that one too, optimally in sync with the plugin version. It is no hard requirement, but I think it makes sense.
  • Maybe you even want to upgrade to the current version AspectJ 1.8.4, in the plugin as well as the runtime. This can also be achieved by adding a dependency to the desired aspectjtools version to the plugin configuration:
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.source-target.version>1.8</java.source-target.version>
        <aspectj.version>1.8.4</aspectj.version>
    </properties>

    <build>
        <pluginManagement>
             <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.7</version>
                    <configuration>
                        <showWeaveInfo>true</showWeaveInfo>
                        <source>${java.source-target.version}</source>
                        <target>${java.source-target.version}</target>
                        <Xlint>ignore</Xlint>
                        <complianceLevel>${java.source-target.version}</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>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>${aspectj.version}</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
    </dependencies>
Hermia answered 11/11, 2014 at 14:8 Comment(4)
Thank you for answer. I tried to use your configuration, but still get previous result ("[ERROR] PESSIMISTIC_WRITE cannot be resolved or is not a field", "[ERROR] The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<Entitle>)" and other errors like this). Maybe aspectj compiler different from javac and has some problems with enums and etc.?Frig
Can you give me access to your project via GitHub or similar? I have done quite a few things with AJMaven plugin ans AJ itself, so maybe I can help you better when I see the actual code. We can also make a private arrangement if a public repo is not possible.Hermia
I forked your repo at github.com/kriegaex/test-aspectj, but even after removing the parent POM (which I do not have) and manually setting dummy values to liferay parameters, I cannot build because I have no access to your Maven repo at maven.elcom.spb.ru, probably because it is an internal repo. Besides, you have committed your Maven 'target' folder to Git, which you should not have done. I have removed it in my fork. Can you please provide me with a stand-alone project reproducing your problem? I do not even get as far as seeing the real problem.Hermia
I just noticed your last comment after having explained in my new answer why this works and what is really wrong.Hermia
H
6

Having looked at your Maven project https://github.com/dmitrievanthony/test-aspectj I found out that

  • the problem is totally unrelated to AspectJ Maven Plugin,
  • the same compilation errors also occur in Maven Compiler Plugin and
  • that the root cause of your problem is simply bad dependency management.

Here is a screenshot (full size here) from IntelliJ IDEA's "find class":

Class LockModeType is found 3x in the project

As you can see, class LockModeType is found in 3 (three!) dependencies, one of which contains a version of the class which does not contain the expected enum values. Your code compiles if you remove this dependency.

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>ejb3-persistence</artifactId>
        <version>1.0.2.GA</version>
    </dependency>

Maybe you should clean up your dependencies. You can use the Maven Dependency Plugin with goals like dependency:analyze and dependency:tree for that purpose.

Hermia answered 12/11, 2014 at 12:38 Comment(0)
F
1

It will be work after change plugin configuration to following:

<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>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <complianceLevel>1.7</complianceLevel>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </execution>
    </executions>
</plugin>

But after this I get a lot of different compilation errors:

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.6:compile (default) on project tvbs-portlet: Compiler errors:
[ERROR] error at Entitle.class, entitleId, LockModeType.PESSIMISTIC_WRITE);
[ERROR]
[ERROR] /Users/<...>/ejb/BillingEJB.java:43:0::0 PESSIMISTIC_WRITE cannot be resolved or is not a field
[ERROR] error at .createQuery("select e from Entitle e " +
[ERROR]
[ERROR] /Users/<...>/ejb/EntitleEJB.java:62:0::0 The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<Entitle>)
[ERROR] error at return entityManager.createQuery(
[ERROR] ^^

Can cause is incorrect aspectj plugin parameters?

Frig answered 11/11, 2014 at 12:19 Comment(1)
Add <Xlint>ignore</Xlint>Violetavioletta
S
0

make sure the modules has source code,like *.java etc. when i compile CAS on version 4.0.6 it happens this error, I found the cas-server-uber-webapp doesn't has any source code in src folder. just remove the module from parent pom.xml.

Subacute answered 23/12, 2016 at 2:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.