如何使用JPA-Entities作为Maven的依赖项

时间:2019-07-11 14:06:27

标签: java hibernate maven jpa

我进入了multimodule-maven-project一个实体项目,其中有一些Entity和DAO类。还有一些集成测试,我想在一个名为entities-IT的项目中进行单独测试。 现在,我将entities-project作为entites-IT-project的依赖项,但是如果我运行构建,则会出现如下错误消息:

return await Task.FromResult<DataModel>(new DataModel());

这很奇怪,因为在目标文件夹中有所有提到的.class文件,并且文件夹结构也正确。

如果在其他项目中使用实体作为依赖项,有什么需要注意的东西吗?

在entities-project的[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project entities-IT: Compilation failure [ERROR] /some/path/to/project/entities-IT/src/it/java/com/example/persistence/dao/ExampleDaoIT.java:[25,38] cannot access com.example.persistence.ExampleEntity [ERROR] bad class file: /some/path/to/project/persistence/ExampleEntity.class [ERROR] illegal start of class file [ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath. 中,正在进行一些代码生成:

pom.xml

然后在实体-IT项目中设置了依赖项:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <compilerArguments>
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
            </compilerArguments>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>2.2.4</version>
        <executions>
            <execution>
                <id>process</id>
                <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
                <compilerArguments>
                    -Aeclipselink.persistencexml=${project.basedir}/src/main/java/META-INF/persistence.xml
                </compilerArguments>
                <processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
                    </processor>
                </processors>
            </configuration>
        </execution>
    </executions>
</plugin>
</plugins>
...
</build>

并使用failsafe插件运行测试:

<dependency>
     <groupId>example</groupId>
     <artifactId>entities</artifactId>
     <version>${parent.version}</version>
</dependency>

0 个答案:

没有答案