Pet*_*zov 5 java hibernate maven
我想配置hibernate-jpamodelgen
到 Maven 中pom.xml
。我试过这个:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>plugin</groupId>
<artifactId>org.plugin</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Plugin</name>
<url>http://maven.apache.org</url>
<parent>
........
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.3.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>datalis_plugin</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>10</source>
<target>10</target>
<encoding>${project.build.sourceEncoding}</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</path>
</annotationProcessorPaths>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
完整 POM:https: //pastebin.com/VjucMAYL
但我收到错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project org.plugin: Compilation failure
[ERROR] Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found
Run Code Online (Sandbox Code Playgroud)
你知道我该如何解决这个问题吗?
我用过这个: https: //docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single/
小智 7
我通常只是将 hibernate-jpamodelgen 添加到编译器插件的注释处理器路径中。这会阻止处理器被打包到部署中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.3.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果是 Java 12,请在 pom.xml 的 build 中使用以下代码片段。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
之后,为 jpamodelgen 添加以下内容。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.3.Final</version>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)