在 Maven 中配置 hibernate-jpamodelgen

我想配置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>

完整 POM: https: //pastebin.com/VjucMAYL



慕码人8056858
浏览 233回答 4
4回答

偶然的你

我通常只是将 hibernate-jpamodelgen 添加到编译器插件的 annotationprocessorpath 中。这可以防止处理器被打包到部署中。&nbsp;<plugin>&nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; <annotationProcessorPaths>&nbsp; &nbsp; &nbsp; &nbsp; <path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.mapstruct</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>mapstruct-processor</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>${org.mapstruct.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; </path>&nbsp; &nbsp; &nbsp; &nbsp; <path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>5.4.3.Final</version>&nbsp; &nbsp; &nbsp; &nbsp; </path>&nbsp; &nbsp; &nbsp; </annotationProcessorPaths>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </configuration>&nbsp; </plugin>

料青山看我应如是

<scope>provided</scope>从中删除&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>5.4.3.Final</version>&nbsp; &nbsp; </dependency>添加插件&nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.bsc.maven</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-processor-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.1.0</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>process</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>process</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>generate-sources</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <processors>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </processors>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>5.4.3.Final</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dependencies>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; </plugins>然后重建mvn clean package -DskipTests

陪伴而非守候

如果是 Java 12,请在 pom.xml 中的构建中使用以下代码片段。<plugin>&nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; <version>3.8.0</version>&nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; <release>12</release>&nbsp;&nbsp;&nbsp; &nbsp; </configuration></plugin>在此之后,为 jpamodelgen 添加以下内容。<dependency>&nbsp; <groupId>org.hibernate</groupId>&nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; <version>5.4.3.Final</version>&nbsp; <optional>true</optional></dependency>

眼眸繁星

这对我有用pom.xml:<dependencies>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>provided</scope>&nbsp; &nbsp; </dependency></dependencies><build>&nbsp; <plugins>&nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source>11</source>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <target>11</target>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <annotationProcessorPaths>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-configuration-processor</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>2.2.11.RELEASE</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>5.4.22.Final</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </path>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </annotationProcessorPaths>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; </plugins></build><profiles>&nbsp; <profile>&nbsp; &nbsp; &nbsp; &nbsp; <id>dev</id>&nbsp; &nbsp; &nbsp; &nbsp; <activation>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <activeByDefault>true</activeByDefault>&nbsp; &nbsp; &nbsp; &nbsp; </activation>&nbsp; &nbsp; &nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; </dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <properties>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <spring.profiles.active>dev</spring.profiles.active>&nbsp; &nbsp; &nbsp; &nbsp; </properties>&nbsp; &nbsp; </profile></profiles>import com.mycompany.myapp.domain.*; // for static metamodelsimport com.mycompany.myapp.domain.Userpublic class UserQueryService {private Specification<User> createSpecification(UserCriteria criteria) {&nbsp; Specification<User> specification = Specification.where(null);&nbsp; if (criteria != null) {&nbsp; &nbsp; if (criteria.getId() != null) {&nbsp; &nbsp; &nbsp; &nbsp;specification = specification.and(buildSpecification(criteria.getId(), User_.id));&nbsp; &nbsp; }&nbsp; }&nbsp; return specification;}&nbsp; &nbsp;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java