Jooq 自定义代码生成器策略的类路径问题

问题描述 投票:0回答:1

我正在尝试使用自定义代码生成器策略运行 Jooq 代码生成。使用匹配器规则是有效的,但对于我的情况来说太有限了。代码生成由 Maven 调用,其配置嵌入在 POM 中,自定义策略的源代码也是如此:

...
<build>
    <plugins>
        ...

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

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

            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>42.7.3</version>
                </dependency>
            </dependencies>

            <configuration>

                <jdbc>
                    <driver>org.postgresql.Driver</driver>
                    <url>jdbc:postgresql://localhost:5432/user_management</url>
                    <user>postgres</user>
                    <password>postgres</password>
                </jdbc>

                <generator>
                    <database>
                        <name>org.jooq.meta.postgres.PostgresDatabase</name>
                        <includes>.*</includes>
                        <schemata>
                            <schema>
                                <inputSchema>user_management</inputSchema>
                            </schema>
                        </schemata>
                    </database>

                    <generate/>

                    <strategy>
                        <name>name.martingeisse.user_management.jooq_config.MyDatabaseStrategy</name>
                        <java>
                            package name.martingeisse.user_management.jooq_config;

                            import static org.jooq.impl.DSL.*;
                            import org.jooq.*;
                            import org.jooq.Record; // Starting with Java 14, Record can not be imported on demand anymore
                            import org.jooq.impl.*;
                            import org.jooq.codegen.DefaultGeneratorStrategy;

                            public class MyDatabaseStrategy extends DefaultGeneratorStrategy {

                                @Override
                                public String getJavaIdentifier(Definition definition) {
                                    return definition.getOutputName();
                                }

                                @Override
                                public String getJavaSetterName(Definition definition, Mode mode) {
                                    return "set" + org.jooq.tools.StringUtils.toLC(definition.getOutputName());
                                }

                                @Override
                                public String getJavaGetterName(Definition definition, Mode mode) {
                                    return "get" + org.jooq.tools.StringUtils.toLC(definition.getOutputName());
                                }

                                @Override
                                public String getJavaMethodName(Definition definition, Mode mode) {
                                    return "call" + org.jooq.tools.StringUtils.toLC(definition.getOutputName());
                                }

                                @Override
                                public String getJavaClassName(Definition definition, Mode mode) {
                                    return definition.getOutputName();
                                }

                                @Override
                                public String getJavaMemberName(Definition definition, Mode mode) {
                                    return definition.getOutputName();
                                }

                            }
                        </java>


                    </strategy>

                    <target>
                        <packageName>name.martingeisse.user_management.jooq.user_management.jooq</packageName>
                        <directory>target/generated-sources/jooq</directory>
                    </target>
                    
                </generator>

            </configuration>
        </plugin>
    </plugins>
</build>
...

错误:

[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.19.9:generate (default) on project usermanagement-experiment-backend: Error running jOOQ code generation tool: Compilation error: /name/martingeisse/user_management/jooq_config/MyDatabaseStrategy.java:7: error: package org.jooq.codegen does not exist
[ERROR]                                 import org.jooq.codegen.DefaultGeneratorStrategy;
[ERROR]                                                        ^
[ERROR] /name/martingeisse/user_management/jooq_config/MyDatabaseStrategy.java:9: error: cannot find symbol
[ERROR]                                 public class MyDatabaseStrategy extends DefaultGeneratorStrategy {
[ERROR]                                                                         ^
[ERROR]   symbol: class DefaultGeneratorStrategy
[ERROR] /name/martingeisse/user_management/jooq_config/MyDatabaseStrategy.java:12: error: cannot find symbol
[ERROR]                                     public String getJavaIdentifier(Definition definition) {
[ERROR]                                                                     ^
[ERROR]   symbol:   class Definition
[ERROR]   location: class MyDatabaseStrategy
... (more of the same)

如何使 codegen 包可用于我的自定义策略?

java jooq jooq-codegen-maven jooq-codegen
1个回答
0
投票

不确定为什么传递依赖项不可用于您的插件执行,但您始终可以将它们明确地放在插件类路径中,即:

<plugin>

    <!-- .. -->
    <dependencies>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>${jooq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>${jooq.version}</version>
        </dependency>
    </dependencies>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.