调试 "Incorrect configuration of jOOQ code generation tool"

Debugging "Incorrect configuration of jOOQ code generation tool"

我正在尝试按照 jOOQ 教程进行操作。我在 Step 3(代码生成)但想使用 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>net.hiew</groupId>
    <artifactId>jooq-tutorial</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>1.1.7</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- Specify the maven code generator plugin -->
                <!-- Use org.jooq            for the Open Source Edition
                         org.jooq.pro        for commercial editions,
                         org.jooq.pro-java-6 for commercial editions with Java 6 support,
                         org.jooq.trial      for the free trial edition

                     Note: Only the Open Source Edition is hosted on Maven Central.
                           Import the others manually from your distribution -->
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>3.11.2</version>

                <executions>
                    <execution>
                        <id>jooq-codegen</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <!-- Configure the database connection here -->
                            <jdbc>
                                <driver>org.mariadb.jdbc.Driver</driver>
                                <url>jdbc:mariadb://localhost:3306/library</url>
                                <user>root</user>
                                <password>mysql</password>
                            </jdbc>

                            <generator>
                                <!-- The default code generator. You can override this one, to generate your own code style.
                                     Supported generators:
                                     - org.jooq.codegen.JavaGenerator
                                     - org.jooq.codegen.ScalaGenerator
                                     Defaults to org.jooq.codegen.JavaGenerator -->
                                <name>org.jooq.codegen.JavaGenerator</name>

                                <database>
                                    <!-- The database type. The format here is:
                                         org.util.[database].[database]Database -->
                                    <name>org.jooq.meta.mariadb.MariaDBDatabase</name>

                                    <!-- The database schema (or in the absence of schema support, in your RDBMS this
                                         can be the owner, user, database name) to be generated -->
                                    <inputSchema>library</inputSchema>

                                    <!-- All elements that are generated from your schema
                                         (A Java regular expression. Use the pipe to separate several expressions)
                                         Watch out for case-sensitivity. Depending on your database, this might be important! -->
                                    <includes>.*</includes>

                                    <!-- All elements that are excluded from your schema
                                         (A Java regular expression. Use the pipe to separate several expressions).
                                         Excludes match before includes, i.e. excludes have a higher priority -->
                                    <excludes></excludes>
                                </database>

                                <target>
                                    <!-- The destination package of your generated classes (within the destination directory) -->
                                    <packageName>net.hiew.jooqtutorial.generated</packageName>

                                    <!-- The destination directory of your generated classes. Using Maven directory layout here -->
                                    <directory>/home/james/src/local/jooqtutorial/src/main/java/</directory>
                                </target>
                            </generator>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我的项目目录:

我在 运行 mvn -e jooq-codegen:generate:

时得到的错误
[INFO] --- jooq-codegen-maven:3.11.2:generate (default-cli) @ jooq-tutorial ---                                                                                                                              
[ERROR] Incorrect configuration of jOOQ code generation tool                                                                                                                                                 
[ERROR]                                                                                                                                                                                                      
The jOOQ-codegen-maven module's generator configuration is not set up correctly.                                                                                                                             
This can have a variety of reasons, among which:                                                                                                                                                             
- Your pom.xml's <configuration> contains invalid XML according to jooq-codegen-3.11.0.xsd                                                                                                                   
- There is a version or artifact mismatch between your pom.xml and your commandline

错误消息没有多大帮助,所以我不确定进一步调试问题的最佳方法。 pom.xml 验证并且数据库存在并且可以访问,如 <configuration> 元素中所述。

替代, you could rename your executionId to default-cli as documented here。所以,这应该有效:

<executions>
    <execution>
        <id>default-cli</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <!-- Configure the database connection here -->
            <jdbc>
            ...

另一个我一直喜欢的选项是使用配置文件:

<profiles>
    <profile>
        <id>jooq-codegen</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-codegen-maven</artifactId>
                    <version>3.11.2</version>
                    ...

然后,运行 与

mvn install -P jooq-codegen

配置标签必须直接在插件标签下,而不是在执行内部:

<plugin>
  ...
  <executions>
     ...
  </executions>

  <configuration>
     ...
  </configuration>
  ...
</plugin>

完整插件标签:

<plugin>
  <!-- Specify the maven code generator plugin -->
  <!-- Use org.jooq            for the Open Source Edition             org.jooq.pro        for commercial editions,             org.jooq.pro-java-6 for commercial editions with Java 6 support,             org.jooq.trial      for the free trial edition         Note: Only the Open Source Edition is hosted on Maven Central.               Import the others manually from your distribution -->
  <groupId>org.jooq</groupId>
  <artifactId>jooq-codegen-maven</artifactId>
  <version>3.11.2</version>

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

  <dependencies>
    <dependency>
      <groupId>org.mariadb.jdbc</groupId>
      <artifactId>mariadb-java-client</artifactId>
      <version>${mariadb.version}</version>
    </dependency>
  </dependencies>

  <configuration>
    <!-- Configure the database connection here -->
    <jdbc>
      <driver>org.mariadb.jdbc.Driver</driver>
      <url>jdbc:mariadb://localhost:3306/library</url>
      <user>root</user>
      <password>mysql</password>
    </jdbc>

    <generator>
      <!-- The default code generator. You can override this one, to generate your own code style.                     Supported generators:                     - org.jooq.codegen.JavaGenerator                     - org.jooq.codegen.ScalaGenerator                     Defaults to org.jooq.codegen.JavaGenerator -->
      <name>org.jooq.codegen.JavaGenerator</name>
      <database>
        <!-- The database type. The format here is:                         org.util.[database].[database]Database -->
        <name>org.jooq.meta.mariadb.MariaDBDatabase</name>
        <!-- The database schema (or in the absence of schema support, in your RDBMS this                         can be the owner, user, database name) to be generated -->
        <inputSchema>library</inputSchema>
        <!-- All elements that are generated from your schema                         (A Java regular expression. Use the pipe to separate several expressions)                         Watch out for case-sensitivity. Depending on your database, this might be important! -->
        <includes>.*</includes>
        <!-- All elements that are excluded from your schema                         (A Java regular expression. Use the pipe to separate several expressions).                         Excludes match before includes, i.e. excludes have a higher priority -->
        <excludes>
        </excludes>
      </database>
      <target>
        <!-- The destination package of your generated classes (within the destination directory) -->
        <packageName>net.hiew.jooqtutorial.generated</packageName>
        <!-- The destination directory of your generated classes. Using Maven directory layout here -->
        <directory>/home/james/src/local/jooqtutorial/src/main/java/</directory>
      </target>
    </generator>

  </configuration>

</plugin>

请注意,您可能需要在依赖项中指定您的 mariadb 版本,我添加了默认变量名称。