jooq-codegen-maven插件和JDK9编译错误

时间:2017-09-21 22:55:16

标签: maven jooq java-9

我刚刚将我的项目表单JDK8升级到JDK9。我使用JOOQ库版本3.9.5。我现在在编译时看到这个错误。

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/database.properties</exclude>
            </excludes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/main/resources/database.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>${flyway.version}</version>

            <!-- Note that we're executing the Flyway plugin in the "generate-sources" phase -->
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>migrate</goal>
                    </goals>
                </execution>
            </executions>

            <!-- Note that we need to prefix the db/migration path with filesystem: to prevent Flyway
                 from looking for our migration scripts only on the classpath -->
            <configuration>
                <driver>${db.driver}</driver>
                <url>${db.url}</url>
                <user>${db.username}</user>
                <password>${db.password}</password>
                <locations>
                    <location>filesystem:src/main/resources/db/migration</location>
                </locations>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen-maven</artifactId>
            <version>${org.jooq.version}</version>

            <!-- The plugin should hook into the generate goal -->
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
                <!--<execution>-->
                <!--<goals>-->
                <!--<goal>generate</goal>-->
                <!--</goals>-->
                <!--</execution>-->
            </executions>

            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgresql.version}</version>
                </dependency>
            </dependencies>

            <configuration>
                <jdbc>
                    <driver>${db.driver}</driver>
                    <url>${db.url}</url>
                    <user>${db.username}</user>
                    <password>${db.password}</password>
                </jdbc>

                <generator>
                    <name>org.jooq.util.JavaGenerator</name>
                    <strategy>
                        <name>com.myproject.dbms.jooq.conf.RemoveColumnPrefixDatabaseStrategy</name>
                    </strategy>

                    <database>
                        <name>org.jooq.util.postgres.PostgresDatabase</name>
                        <!--force generating id'sfor everything in public schema, that has an 'id' field-->
                        <includes>.*</includes>
                        <excludes></excludes>

                        <schemata>
                            <schema>
                                <inputSchema>commons</inputSchema>
                            </schema>
                        </schemata>

                        <unsignedTypes>false</unsignedTypes>

                        <customTypes>
                            <customType>
                                <name>Json</name>
                                <type>com.google.gson.JsonElement</type>
                                <binding>com.myproject.dbms.jooq.databinding.PostgresJSONGsonBinding</binding>
                            </customType>
                        </customTypes>
                        <forcedTypes>
                            <forcedType>
                                <name>Json</name>
                                <types>json</types>
                            </forcedType>
                            <forcedType>
                                <name>NUMERIC(8,2)</name>
                                <expression>shop.localized_money.lm_amount</expression>
                                <types>.*</types>
                            </forcedType>
                        </forcedTypes>

                      <generate>
                        <!--<javaTimeTypes/>-->
                        <deprecated>false</deprecated>
                        <relations>true</relations>
                        <generatedAnnotation>false</generatedAnnotation>
                        <instanceFields>true</instanceFields>
                        <records>true</records>
                        <interfaces>false</interfaces>
                        <pojos>true</pojos>
                        <immutablePojos>false</immutablePojos>
                        <daos>false</daos>
                        <jpaAnnotations>true</jpaAnnotations>
                        <springAnnotations>true</springAnnotations>
                        <validationAnnotations>true</validationAnnotations>
                        <globalObjectReferences>true</globalObjectReferences>
                        <fluentSetters>true</fluentSetters>
                        <pojosEqualsAndHashCode>true</pojosEqualsAndHashCode>
                        <globalUDTReferences>true</globalUDTReferences>
                    </generate>

                    <target>
                        <packageName>com.myproject.model.jooq</packageName>
                        <!--<directory>src/main/java</directory>-->
                    </target>
                </generator>
            </configuration>
        </plugin>
    </plugins>
</build>

在构建部分我有

awk '$5 ~ /gene_name/ {print $2, $6}'

有什么想法吗?可能它是jOOQ插件中的旧传递依赖?也许this页可能会有所帮助。

3 个答案:

答案 0 :(得分:5)

显然,jooq-codegen-maven插件使用JAXB API,可以在the Java EE module java.xml.bind中找到。但是,Java EE modules are not resolved by default(也已弃用),这解释了为什么JVM抱怨它无法找到JAXBException

澄清一下:运行Maven进程的JVM缺少依赖关系,它启动的编译!

短期修复是手动将依赖项--add-modules 添加到执行插件的JVM

  • 如果插件允许分叉(即可以在运行Maven进程的JVM中执行另一个JVM),您可以在POM中向其添加--add-modules java.xml.bind。快速搜索表明这可能是不可能的。
  • 否则,您需要配置运行Maven进程的JVM,您可以使用the poorly documented .mvn/jvm.config file进行操作。只需将此类文件添加到启动构建的目录(可能是包含您的POM的目录)中,然后将--add-modules java.xml.bind放入其中。 (不幸的副作用:你不能再用Java 8构建了。)

有关第二种方法的更多详细信息,请查看this newsletter that I wrote

答案 1 :(得分:3)

Version 3.10.0 - September 29, 2017

只需将此标记为日期,您现在可以使用JOOQ库版本3.10.0

  

..是第一个与Java 9正式集成测试的版本   以及Java 6/7和Java 8的现有集成测试。   要在Java 9中使用 jOOQ,请使用尚未使用的Java 8发行版   已经模块化,但包含自动模块名称规范   与未来的模块化jOOQ发行版向前兼容。

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

答案 2 :(得分:0)

如果仅用于构建,那么我可以通过构建JDK 11 Hotspot来构建Sping-Boot 2.0.3.RELEASE目标,而Jre 8是目标。

            <plugin>
              <groupId>org.jooq</groupId>
              <artifactId>jooq-codegen-maven</artifactId>
              <executions>
                <execution>
                    <id>jooq-codegen</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
              </executions>
              <dependencies>
                <dependency>
                    <groupId>javax.xml.bind</groupId>
                    <artifactId>jaxb-api</artifactId>
                    <version>2.4.0-b180830.0359</version>
                </dependency>
                ...
              </dependencies>
              ...
            </plugin>