jOOQ 和 Spring 引导 pom.xml 配置问题

jOOQ and Spring Boot pom.xml configuration problem

我正在尝试在 pom.xml 中使用以下配置设置 jOOQ 和 Spring 引导项目:

当我 运行 mvn package -Pgenerate 创建 类 时,我收到一条消息说

[WARNING] The requested profile "generate" could not be activated because it does not exist.

尽管有警告,构建仍完成,但 target/generated-sources/jooq 文件夹中和 src 文件夹中的任何地方都没有生成 类。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jooq -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jooq</artifactId>
            <version>2.3.0.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.20</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>

                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>3.13.2</version>

                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>

                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.20</version>
                    </dependency>
                </dependencies>

                <configuration>

                    <jdbc>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/visitorlog?serverTimezone=UTC</url>
                        <user>root</user>
                        <password>root</password>
                    </jdbc>

                    <generator>
                        <database>
                            <name>org.jooq.meta.mysql.MySQLDatabase</name>
                            <includes>.*</includes>
                            <excludes></excludes>
                            <!-- In case your database supports catalogs, e.g. SQL Server:
                            <inputCatalog>public</inputCatalog>
                              -->
                            <inputSchema>public</inputSchema>
                        </database>
                        <target>
                            <packageName>com.demo.example.demo</packageName>
                            <directory>target/generated-sources/jooq</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>
        </plugins>


    </build>

</project>

-Pgenerate 表示激活配置文件生成但您没有配置文件生成。

您可能想要做的是运行 jOOQ 代码生成

mvn jooq-codegen:generate

这也可以像这样绑定到 Maven 阶段:

<execution>
    <id>jooq-codegen</id>
    <phase>generate-sources</phase>
    <goals>
       <goal>generate</goal>
    </goals>
</execution>

所以当你进行 maven 编译时,它也会生成 jOOQ 代码。