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

Jen*_*ger 6 hibernate jpa aspectj maven aspectj-maven-plugin

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

<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>
Run Code Online (Sandbox Code Playgroud)

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

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_ {

...
Run Code Online (Sandbox Code Playgroud)

我怎样才能阻止AspectJ编译器第二次执行模型生成器?

Jen*_*ger 1

我从aspectj编译器中排除了模型类。这会禁用模型类的方面(当前不需要),还会禁用元模型类的双重生成:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <configuration>
                <sources>
                    <source>
                        <basedir>src/main/java</basedir>
                        <excludes>
                            <exclude>**/domain/*</exclude>
                        </excludes>
                    </source>
                </sources>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)