Adding AspectJ to pom.xml changed Java version with Maven, why? - java

UPDATE: here is my maven-compiler-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
I work on a multi-project application that I build with Maven. We decided to add AspectJ so I added the following code to pom.xml in the top level project: (from the official documentation)
<project>
...
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>
...
</project>
and the following fragments to each subordinate projects:
</project>
...
<build>
....
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
....
</dependencies>
...
</project>
Somehow this modification has overridden the Java version I use. If I run build I get multiple errors like this:
Syntax error, annotations are only available if source level is 1.5 or greater
That gives me the suspicion that my Java version (originally 1.6) was somehow reverted to 1.4. I did nothing - at least not knowingly - that could influence the Java version, so I suspect that the above mentioned AspectJ related code is responsible for the change.
My question is how can AspectJ change the Java version and what should I do to fix this problem. Or do I misunderstand something completely and am I on the wrong track?

I think the problem is with the default source, target and complianceLevel settings of the aspectj-maven-plugin (according to the documentation linked previously, 1.4, 1.2 and 1.4 respectively). You should set these explicitly in your parent pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<!-- new configuration is here -->
<configuration>
<complianceLevel>1.6</complianceLevel>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<build>

I was missing
<complianceLevel>${java.level}</complianceLevel>
in my pom.xml

If you don't have define the version, the compiler plugin assumes that your Java source conforms to Java 1.3 and that you are targeting a Java 1.1 JVM.
Maybe, you should define it:
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

You can find last versions of dependecy and plugin for aspectj.

I was missing the java version with jdk version at the top of my pom properties.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version> <!-- 1.5 dint work for me -->
<dependencies>
<!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-sources</phase> <!-- or any phase before compile -->
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${jdk.version}</source> <!-- I was missing this -->
<target>${jdk.version}</target> <!-- jdk.version property -->
</configuration>
</plugin>
and at the top of my pom.xml I had set jdk.version property like,
<properties>
<jdk.version>1.7</jdk.version>
</properties>

Related

Maven AspectJ plugin fails to build with Java 9 due to missing tools.jar

I switched my JDK version from 8 to 9 and the AspectJ plugin no longer works due to missing tools.jar:
Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.10:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.10 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:9.0.1 at specified path C:\Program Files\Java\jdk-9.0.1/../lib/tools.jar
I understand that tools.jar (and rt.jar) were removed from Java 9 JDK. I am wondering if there a way to get Maven AspectJ plugin to work with Java 9 without tools.jar?
Here is my plugin definition with version info:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<complianceLevel>1.9</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<XnoInline>true</XnoInline>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.0.RC2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.9.0.RC2</version>
</dependency>
</dependencies>
</plugin>
I just found an ugly trick to make aspectj working with Java 9, just point com.sun:tools to the pom.xml and the compiler just run.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<weaveDependencies>
<weaveDependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</weaveDependency>
</weaveDependencies>
<showWeaveInfo>true</showWeaveInfo>
<XnoInline>true</XnoInline>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/pom.xml</systemPath>
</dependency>
</dependencies>
</plugin>
Until version 1.11.1 is released into Maven Central by org.codehaus.mojo use the snapshot build instead:
<groupId>com.github.m50d</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11.1</version>
Ran into the same issue, the problem is that this transitive dependency is active by default in the aspectj-maven-plugin.
Fixed it for me with this PR
https://github.com/mojohaus/aspectj-maven-plugin/pull/35
Have you checked the newest plugin version?
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>

karaf-assembly 4.0.5 - zip ard tar.gz files are not generated at the end of a successful maven build

I am an inexperienced Java and Maven developer, although I have got karaf-assembly builds to work a couple of years ago using the Karaf 3.0.1 release.
When attempting to generating a karaf-assemby 4.0.5 for a customised product build, the zip and tar.gz files are not created at the end of the maven build. The ../target/assembly directory is created each time the maven build is run and the completion status is always "BUILD SUCCESS".
I suspect this this is because the POM file has an error highlighted by the Eclipse IDE at the section for the karaf-maven-plugin directly on the line, which is as follows:
Plugin execution not covered by lifecycle configuration: org.apache.karaf.tooling:karaf-maven-plugin:4.0.5:assembly (execution: default-assembly, phase: process-
resources)
I can resolve this error in the IDE on the line by removing the "extensions" line, but then I get a "Project build error: Unknown packaging: karaf-assembly" error on the "packaging" line.
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
**<!-- <extensions>true</extensions> -->**
<configuration>
<startupFeatures></startupFeatures>
<bootFeatures>
<feature>standard</feature>
<feature>management</feature>
<feature>jms</feature>
</bootFeatures>
<installedFeatures>
</installedFeatures>
</configuration>
</plugin>
The POM file I am using is as follows:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.custom</groupId>
<artifactId>my.distribution</artifactId>
<version>1.0</version>
<packaging>karaf-assembly</packaging>
<!-- PIP Operations Aspect Assembly properties -->
<properties>
<maven-compiler-plugin-version>2.3.2</maven-compiler-plugin-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<assembly.directory>${project.build.directory}/assembly/karaf-4.0.5</assembly.directory>
<karaf.name>karaf</karaf.name>
<karaf.version>4.0.5</karaf.version>
<pip.name>Operations Aspect</pip.name>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.0.5</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.0.5</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<classifier>features</classifier>
<version>4.0.5</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<classifier>features</classifier>
<version>4.0.5</version>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>process-resources</id>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.5</version>
<extensions>true</extensions>
<configuration>
<startupFeatures></startupFeatures>
<bootFeatures>
<feature>standard</feature>
<feature>management</feature>
<feature>jms</feature>
</bootFeatures>
<installedFeatures>
</installedFeatures>
</configuration>
</plugin>
</plugins>
</build>
Any suggestions would be gratefully received.
You might be missing the execution settings:
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
<execution>
<id>package</id>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>

How to disable AspectJ compilation via configuration

I implement my aspect class in Java style:
#Aspect
public class SomeAspect {
#Pointcut("...")
public void somePointcut() {}
#Around("somePointcut()")
public ...
}
I am new to AspectJ. I want to know if there a convenient/centralized way to control the effectiveness of the Pointcut so I can enable/disable them based on some configuration at compile time.
During runtime you can just use an if() pointcut, but I know this is not what you want.
For compile time it depends on how you build your project. I am going to assume you use Maven and the AspectJ Maven Plugin.
Let us further assume that you configure the plugin to run in the process-sources phase like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</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>${project.build.sourceEncoding}</encoding>
<!--<verbose>true</verbose>-->
<!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>-->
</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>
Then just add a Maven profile - let us call it skip-aspectj which overwrites the phase to none via <phase/>:
<profiles>
<profile>
<id>skip-aspectj</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<phase/>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Now if you run your Maven build
normally, the aspects are compiled and applied,
with mvn -P skip-aspectj ... they will be inactive and the whole AspectJ Maven execution just skipped.

How to make JAXB to annotate and provide equlas/hash code implementation

I am trying to use JAXB to generate classes from WSDL which are annotated with Jsr303Annotations and provide implementation of equals and hashcode.
Both of these work separately, however when i try to achieve both requirements then i get error:
An internal error occurred during: "Building workspace".
com.sun.tools.xjc.Plugin: Provider org.jvnet.jaxb2_commons.plugin.fixjaxb1058.FixJAXB1058Plugin could not be instantiated: java.lang.NoClassDefFoundError: org/jvnet/jaxb2_commons/reflection/util/Accessor
Could somebody tell me how to configure JAXB to do both of these ?
Bellow is my attempt to do so:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
<!-- <include>*.xsd</include> -->
</schemaIncludes>
<!-- <forceRegenerate>true</forceRegenerate> -->
<!-- <removeOldOutput>true</removeOldOutput> -->
<!-- <cleanPackageDirectories>true</cleanPackageDirectories> -->
<strict>true</strict>
<extension>true</extension>
<args>
<arg>-XJsr303Annotations</arg>
<arg>-Xannotate</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
<plugin>
<groupId>com.github.krasa</groupId>
<artifactId>krasa-jaxb-tools</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
Edit: Relevant dependencies i have tried to use:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.9.4</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!-- <artifactId>jaxb2-basics-annotate</artifactId> -->
<!-- <version>1.0.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.jvnet.jaxb2_commons</groupId> -->
<!-- <artifactId>jaxb2-commons-lang</artifactId> -->
<!-- <version>2.3</version> -->
<!-- </dependency> -->
Only the combination of first dependency and plugin for equals/hash code yield result.
If i include the other 2 dependencies then i get missing artifact -id message for every dependency in project.
Plugins for annotations work without explicit dependencies, when used without equals/hashcode plugin and vice versa.
Edit: Final solution in case anyone gets stuck on same issue
So it was required to separate annotations and equals/hash code plugins into separate executions, this resolved all issues.
Found a solution. This plugin requires another one dependency:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.argonio.fias.entity</generatePackage>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<readOnly>true</readOnly>
<removeOldOutput>true</removeOldOutput>
<verbose>true</verbose>
<extension>true</extension>
<args>
<arg>-no-header</arg>
<arg>-Xxew</arg>
<arg>-Xxew:instantiate lazy</arg>
<arg>-Xxew:plural</arg>
<arg>-Xequals</arg>
</args>
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.5</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
</plugins>
</configuration>
<dependencies>
<!-- This dependency is required to execute the plugin -->
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-tools</artifactId>
<version>0.9.4</version>
</dependency>
</dependencies>
</plugin>
Try to add this dependency. By the way, your version 0.6.3 seems low.
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-commons-lang</artifactId>
<version>2.3</version>
</dependency>
The answer of #Viacheslav is correct. Note however that you also need to add a dependency for the project:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.9.4</version> <!-- same as jaxb2-basics plugin version -->
</dependency>
See http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins for all details.

AspectJ Maven Plugin cannot compile my project

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?
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>
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>
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":
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.
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?
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.

Categories