Aspectj插件再次调用JPA模型生成器

Aspectj插件再次调用JPA模型生成器

本文介绍了Maven Aspectj插件再次调用JPA模型生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,使用Hibernate元模型生成器生成JPA元模型.

I have a Maven project where I generate the JPA metamodel using the Hibernate metamodel generator.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>xxx</groupId>
        <artifactId>xxx</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>xxx</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </dependency>

        <dependency>
            <!-- needed for meta model generation (see also compiler plugin config) -->
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>4.3.8.Final</version>
        </dependency>
    </dependencies>
</project>

AspectJ编译器在父项目中配置.当我运行Maven时,将首先调用Java编译器插件,并正确生成target/generated-sources/generated-sources/annotations的源.然后执行AspectJ插件,再次生成源,现在将其插入到我项目的根文件夹中并引发以下错误:

The AspectJ compiler is configured in the parent project. When I run Maven, the Java compiler plugin is called first and generates the sources to target/generated-sources/generated-sources/annotations correctly. Then the AspectJ plugin is executed which generates the sources again, now into the root folder of my project and throws the following errors:

D:\xxx\git\xxx>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xxx ---
[INFO] Deleting D:\...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xxx ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 63 source files to D:\xxx\git\xxx\target\classes
[INFO]
[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ xxx ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] Hibernate JPA 2 Static-Metamodel Generator 4.3.8.Final
        <unknown source file>:<no line information>

[ERROR] The type Category_ is already defined
        D:\xxx\git\xxx\Category_.java:10
public abstract class Category_ extends com.xxx.AbstractEntity_ {
                      ^^^^^^^^

[ERROR] The type Attachment_Message_ is already defined
         D:\xxx\git\xxx\Attachment_Message_.java:9
public abstract class Attachment_Message_ extends com.xxx.AbstractEntity_ {
                      ^^^^^^^^^^^^^^^^^^

[ERROR] The type AbstractNamedEntity_ is already defined
         D:\xxx\git\xxx\AbstractNamedEntity_.java:9
public abstract class AbstractNamedEntity_ extends com.xxx.AbstractEntity_ {

...

如何阻止AspectJ编译器第二次执行模型生成器?

How can I hinder the AspectJ compiler executing the model geneator a second time?

推荐答案

重点是 AspectJ 1.8.2是第一个版本,其中包括导致生成的注释处理功能.

有两种禁用生成的方法:

There are two ways to disable the generation:

  • 1)升级您的Maven-AspectJ-Plugin版本1.8,它具有一个新参数:proc,将其设置为none以禁用该生成.参见 GitHub问题#5

  • 1) Upgrade you Maven-AspectJ-Plugin Version 1.8, it has a new parameter: proc, set it to none to disable the generation. see GitHub Issue #5,

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    ...
    <configuration>
        ...
       <proc>none</proc>
   </configuration>
</plugin>

2)另一种解决方案"是使用AspectJ版本1.8.1,而不是1.8.2 +.

2) One other "solution" would be to use AspectJ Version 1.8.1, but not 1.8.2+.

这篇关于Maven Aspectj插件再次调用JPA模型生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:32