Aspectj Table annotation issues - maven

when I try to add aspectj-maven-plugin inside my existing project, I add this:
[ERROR] The attribute indexes is undefined for the annotation type Table
E:\T2_SupplierPortal_Angular\core\model\src\main\java\com\model\PaymentGrp.java:32
indexes={
^^^^
...
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.8:compile (default) on project model: AJC compiler errors:
error at indexes={
It seems that when I add this plugin, it use an older version of JPA instead of JPA 2.1.
My Configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
<weaveDependencies>
<weaveDependency>
<artifactId>common-logger</artifactId>
<groupId>com.common</groupId>
</weaveDependency>
</weaveDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
</plugin>
I don't know how to solve this. Thank you

Get rid of the syntax error in your source code, then retry the compilation. It is probably not even an AspectJ problem, just a Java syntax problem.

Related

Unable to resolve the class util in gmaven plugin

<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.9.13</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>call-groovy</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>1.8</providerSelection>
<source>src/main/java/test.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
this test.groovy script invokes util methods as below
class test {
util.getDetails()
}
util class is not resolved here even though both are in the same package and throwing the below error
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.5:execute (call-groovy) on project farmer: startup failed:
[ERROR] src/main/java/test.groovy: 7: unable to resolve class FarmerUtility
The error is resolved after adding maven-antrun-plugin which concatenate both the classes

Problem using CriteriaBuilder's isMember method with Kotlin

When using the isMember method of CriteriaBuilder with Kotlin in my application it gives me the following error in the following line:
I've been researching and they always use that form to add a predicate to filter when they need to filter on a list of entity elements.
Do you know what could be happening?
Thank you.
Content_-like classes are generated from corresponding #Entity classes. You need to enable plugin that makes this job done during build. With Maven it could be done like following:
<build>
...
<plugins>
...
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
</build>
After rebuild Content_ (and all similar classes) should appear on classpath

What does Maven, jaxws:wsimport mean when it says '-Xbootclasspath/p is no longer a supported option'?

I have recently had reason to generate Java classes from a WSDL.
I am using Java 15 on Mac, Maven 3.6.3 and JAX-WS 2.3.1.
I get the error
-Xbootclasspath/p is no longer a supported option.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
When trying to generate my sources. What would cause this? and how do I fix it?
Additional info:
My dependencies includes
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.1</version>
<type>pom</type>
</dependency>
My JAX-WS plugin is defined/configured as
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlFiles>
<wsdlFile>
${basedir}/src/main/wsdl/my-wsdl.wsdl
</wsdlFile>
</wsdlFiles>
<packageName>com.example.client</packageName>
<sourceDestDir>src/main/java</sourceDestDir>
</configuration>
</plugin>
It can find my WSDL file. Maven says
[INFO] Processing: file:/Users/user/Development/projects/example/src/main/wsdl/my-wsdl.wsdl
in the logs, before the error.
wsimport was deprecated and replaced in Java 11.
The plugin has been updated to a new version that works with later versions of Java.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
...
</plugin>
will work

aspectj within a maven plugin fails to call pointcut

A = maven plugin I wrote
B = maven project that uses A as part of it's build process
When I use maven to build A, aspectj works as expected and I hit my pointcuts during my unit tests. I use the aspectj-maven-plugin to build it because I build A using maven.
The problem is when I use maven to build B and include A as a plugin dependency, I don't hit my pointcuts while A is executing during the build process.
I have tried include aspectj-maven-plugin in B to solve this, but no luck. I have also tried various forms of configuration in B in attempt to fix this issue. Currently, my configuration for B is as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<forceAjcCompile>true</forceAjcCompile>
<showWeaveInfo>true</showWeaveInfo>
<weaveWithAspectsInMainSourceFolder>true</weaveWithAspectsInMainSourceFolder>
<encoding>UTF-8</encoding>
<aspectLibraries>
<aspectLibrary>
<groupId>com</groupId>
<artifactId>A</artifactId>
</aspectLibrary>
</aspectLibraries>
<weaveDependencies>
<weaveDependency>
<groupId>com</groupId>
<artifactId>A</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>

Eclipselink 2.5 Metamodel Generation using Maven

I would like to know how to generate static metamodels using Maven and Eclipselink 2.5. It worked fine by adding this lines to pom.xml when running Eclipselink 2.4.
// Generate meta model for eclipselink 2.4 (does not work for 2.5)
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<compilerArguments>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArguments>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
</processors>
<outputDirectory>${project.build.directory}/generated-sources/meta-model</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But it seems like something has changed since 2.4 cause I get following error:
[INFO] javac option: -proc:only
[INFO] javac option: -Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml
[INFO] javac option: -processor
[INFO] javac option: org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
[INFO] javac option: -s
[INFO] javac option: /home/asdf/target/generated-sources/meta-model
[INFO] diagnostic error: Annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' not found
[INFO] diagnostic warning: Annotation processing without compilation requested but no processors were found.
[ERROR] execute error
java.lang.Exception: error during compilation
at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled(AbstractAnnotationProcessorMojo.java:183)
at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.execute(AbstractAnnotationProcessorMojo.java:96)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Can you guys out there help me? =)
B.R
It appears that they've moved the CanonicalModelProcessor class to it's own maven artifact:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.0</version>
</dependency>
The following maven-processor-plugin configuration works for me:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>eclipselink-jpa-metamodel</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
</processors>
<outputDirectory>${project.build.directory}/generated-sources/meta-model</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</plugin>
Very important note: the metamodel is generated only if the entities are declared in the persistence unit. It doesn't work with discovered entities.
For me using maven-compiler-plugin from org.apache.maven.plugins resulted in MojoFailureException when using other command than mvn clean install.
The tested the solutions with org.eclipse.persistence.jpa.modelgen.processor 2.6.0.
The configuration in both cases is quite similar.
The main issue which I had with org.bsc.maven was to properly configure the compilerArguments parts. That is why I post (both) the solutions below.
The documentation is available: HERE.
Solution using maven-compiler-plugin from org.bsc.maven
For me this one worked better
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>eclipselink-jpa-metamodel</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<compilerArguments>
-Aeclipselink.persistencexml=${basedir}/src/main/resources/META-INF/persistence.xml
</compilerArguments>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>${eclipselink.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
Solution using maven-compiler-plugin from org.apache.maven.plugins
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>${eclipselink.version}</version>
<scope>compile</scope>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
</compilerArgs>
</configuration>
</plugin>
To make configuration a lot simpler I would recommend you test: https://github.com/ethlo/eclipselink-maven-plugin. You will not even be required to keep an updated persistence.xml file.
<plugin>
<groupId>com.ethlo.persistence.tools</groupId>
<artifactId>eclipselink-maven-plugin</artifactId>
<version>[version]</version>
<executions>
<execution>
<id>weave</id>
<phase>process-classes</phase>
<goals>
<goal>weave</goal>
</goals>
</execution>
<execution>
<id>modelgen</id>
<phase>generate-sources</phase>
<goals>
<goal>modelgen</goal>
</goals>
</execution>
</executions>
</plugin>
Note: I'm the author of the plugin.
2017 UPDATE:
Main answer to this question is now outdated.
You now need to perform the following steps in order to have it work.
1) Import the required dependency:
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa.modelgen.processor -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>compile</scope>
</dependency>
2) Specify persistence.xml location (this is a workaround for an EL bug. Please note that your path may vary from the one specified in this example):
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
[...]
</executions>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgs>
<arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
</compilerArgs>
</configuration>
</plugins>
[...]
</pluginManagement>
[...]
</build>
3) Finally refer to the following item in order to trigger the execution with Maven's new Lifecycle Mappings:
Usage of maven Build Helper Maven Plugin
you're likely to get the following error:
java.lang.RuntimeException: java.lang.SecurityException: class "org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties"'s signer information does not match signer information of other classes in the same package
Because of the unresolved bug compilation is broken, modelgen jar is signed in maven repository, the version must be set to 2.5.0-SNAPSHOT for now.
This is what I used
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
<executions>
<execution>
<id>generate-entity-metamodel</id>
<phase>generate-sources</phase>
<goals>
<goal>
compile
</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<proc>only</proc>
<!--<compilerArgument>-Aeclipselink.metamodel=true</compilerArgument>
<generatedSourcesDirectory>${basedir}/src/main/java</generatedSourcesDirectory>-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-modelgen-generated-sources-directory</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
the add-sources part is for netbeans 8 to understand it to put it in classpath
:)

Resources