在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):etiennestuder/gradle-jooq-plugin开源软件地址(OpenSource Url):https://github.com/etiennestuder/gradle-jooq-plugin开源编程语言(OpenSource Language):Groovy 57.8%开源软件介绍(OpenSource Introduction):gradle-jooq-plugin
OverviewGradle plugin that integrates the jOOQ code generation tool. For each named jOOQ configuration declared in the build, the plugin adds a task to generate the jOOQ sources from the specified database schema and includes the generated Java sources in the matching source set, if existing. The code generation tasks participate in task configuration avoidance, in build configuration caching, in incremental builds, in task output caching, and in toolchains. The plugin can be applied on both Java projects and Android projects. You can find more details about the actual jOOQ source code generation in the jOOQ documentation. The jOOQ plugin is hosted at the Gradle Plugin Portal. Build scanRecent build scan: https://gradle.com/s/zcltzipq7zzha Find out more about build scans for Gradle and Maven at https://scans.gradle.com. FunctionalityThe following functionality is provided by the jOOQ plugin:
The following Gradle configuration changes are contributed by the jOOQ plugin:
The following Gradle features are supported by the jOOQ plugin:
Compatibility
See the Migration section on how to migrate your build from older to newer jOOQ plugin versions. ConfigurationApplying the pluginApply the Gradle Groovy DSLplugins {
id 'nu.studer.jooq' version '7.1.1'
} Gradle Kotlin DSLplugins {
id("nu.studer.jooq") version "7.1.1"
} Adding the database driverAdd the database driver of the database that the jOOQ code generation tool will introspect to the Gradle Groovy DSLdependencies {
jooqGenerator 'org.postgresql:postgresql:42.3.2'
} Gradle Kotlin DSLdependencies {
jooqGenerator("org.postgresql:postgresql:42.3.2")
} Specifying the jOOQ version and editionSpecify the version and edition that should be applied to all jOOQ dependencies that are declared in your project either explicitly or pulled in transitively. Note that the Gradle Groovy DSLjooq {
version = '3.16.4' // the default (can be omitted)
edition = nu.studer.gradle.jooq.JooqEdition.OSS // the default (can be omitted)
} Gradle Kotlin DSLjooq {
version.set("3.16.4") // the default (can be omitted)
edition.set(nu.studer.gradle.jooq.JooqEdition.OSS) // the default (can be omitted)
} Enforcing the jOOQ configuration XML schema versionEnforce a certain version of the jOOQ configuration XML schema by declaring what version of the jOOQ code generation tool to make available to the jOOQ plugin at configuration time, i.e. in the DSL of the jOOQ plugin. Gradle Groovy DSLbuildscript {
configurations['classpath'].resolutionStrategy.eachDependency {
if (requested.group == 'org.jooq') {
useVersion '3.16.1'
}
}
} Gradle Kotlin DSLbuildscript {
configurations["classpath"].resolutionStrategy.eachDependency {
if (requested.group == "org.jooq") {
useVersion("3.16.1")
}
}
} Configuring the jOOQ generation toolConfigure the jOOQ generation tool via By default, the generated sources are written to Gradle Groovy DSLimport org.jooq.meta.jaxb.Logging
jooq {
version = '3.16.4' // default (can be omitted)
edition = nu.studer.gradle.jooq.JooqEdition.OSS // default (can be omitted)
configurations {
main { // name of the jOOQ configuration
generateSchemaSourceOnCompilation = true // default (can be omitted)
generationTool {
logging = Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
url = 'jdbc:postgresql://localhost:5432/sample'
user = 'some_user'
password = 'some_secret'
properties {
property {
key = 'ssl'
value = 'true'
}
}
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
forcedTypes {
forcedType {
name = 'varchar'
includeExpression = '.*'
includeTypes = 'JSONB?'
}
forcedType {
name = 'varchar'
includeExpression = '.*'
includeTypes = 'INET'
}
}
}
generate {
deprecated = false
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'nu.studer.sample'
directory = 'build/generated-src/jooq/main' // default (can be omitted)
}
strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy'
}
}
}
}
} See the Examples section for complete, exemplary build scripts that apply the jOOQ plugin. Gradle Kotlin DSLimport org.jooq.meta.jaxb.ForcedType
import org.jooq.meta.jaxb.Logging
import org.jooq.meta.jaxb.Property
jooq {
version.set("3.16.4") // default (can be omitted)
edition.set(nu.studer.gradle.jooq.JooqEdition.OSS) // default (can be omitted)
configurations {
create("main") { // name of the jOOQ configuration
generateSchemaSourceOnCompilation.set(true) // default (can be omitted)
jooqConfiguration.apply {
logging = Logging.WARN
jdbc.apply {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/sample"
user = "some_user"
password = "some_secret"
properties.add(Property().apply {
key = "ssl"
value = "true"
})
}
generator.apply {
name = "org.jooq.codegen.DefaultGenerator"
database.apply {
name = "org.jooq.meta.postgres.PostgresDatabase"
inputSchema = "public"
forcedTypes.addAll(listOf(
ForcedType().apply {
name = "varchar"
includeExpression = ".*"
includeTypes = "JSONB?"
},
ForcedType().apply {
name = "varchar"
includeExpression = ".*"
includeTypes = "INET"
}
))
}
generate.apply {
isDeprecated = false
isRecords = true
isImmutablePojos = true
isFluentSetters = true
}
target.apply {
packageName = "nu.studer.sample"
directory = "build/generated-src/jooq/main" // default (can be omitted)
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
}
}
}
}
} See the Examples section for complete, exemplary build scripts that apply the jOOQ plugin. Configuring the jOOQ generation task to participate in incremental builds and build cachingIf you configure the state of the database schema from which to derive the jOOQ sources as an input to the jOOQ task, you can mark the
jOOQ task as having all its inputs declared by setting the See here for a complete example on how to enable participation in incremental build and build caching. Gradle Groovy DSL tasks.named('generateJooq').configure { allInputsDeclared = true } Gradle Kotlin DSL tasks.named<nu.studer.gradle.jooq.JooqGenerate>("generateJooq") { allInputsDeclared.set(true) } Configuring the jOOQ generation task with a toolchainIf you configure a toolchain on the project to which the jOOQ task belongs, it is automatically used by the jOOQ task. You can also configure / override the toolchain on the jOOQ task itself. Gradle Groovy DSL tasks.named('generateJooq').configure {
launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(13)
}
} See here for a complete example on how to configure the toolchain to be used by the jOOQ task, using the Gradle DSL. Gradle Kotlin DSL tasks.named<nu.studer.gradle.jooq.JooqGenerate>("generateJooq") {
(launcher::set)(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(13))
})
} Note: See here for a complete example on how to configure the toolchain to be used by the jOOQ task, using the Kotlin DSL. Avoiding configuration pitfallsSynchronizing the jOOQ version between the Spring Boot Gradle plugin and the jOOQ Gradle pluginIt is advisable that the jOOQ Gradle plugin and the Spring Boot Gradle plugin are configured to use the same version of jOOQ. If you want the Spring Boot plugin to pull in the same version of jOOQ as defined by the jOOQ plugin, you have to explicitly set The other way around, if you want the jOOQ plugin to pull in the same version of jOOQ as defined by the Spring Boot plugin, you have to explicitly
set Enforcing dependency versions via dependency rules from third-party plugins or from the build itselfIf the code generation fails with exceptions about not finding certain JAXB classes, it is likely due to a 3rd-party plugin or your own build
adding some dependency rules that enforce certain dependency versions that are not matching what is needed by the jOOQ code generation tool. For
example, the Spring Dependency Management Gradle plugin will downgrade the
Generating sources into shared folders, e.g. src/main/javaMy recommendation is to generate the jOOQ sources into a distinct folder, e.g. src/generated/jooq or build/generated-src/jooq (default). This avoids overlapping outputs, and it also keeps the door open to let Gradle cache the generated sources which can be a significant build performance gain. The rationale is explained very well in the Build Cache User Guide. Configuring a sequence of elements using the Gradle Groovy DSLResemblance of the jOOQ configuration DSL with the Groovy language is coincidental. Complex types that include sequences like ForcedTypes must be defined in the DSL's nesting style: forcedTypes {
forcedType {
name = 'varchar'
expression = '.*'
types = 'JSONB?'
}
forcedType {
name = 'varchar'
expression = '.*'
types = 'INET'
}
} The Groovy list style is not supported: forcedTypes = [
{
name = 'varchar'
expression = '.*'
types = 'JSONB?'
},
{
name = 'varchar'
expression = '.*'
types = 'INET'
}
] Working with Configurations in the Kotlin DSLSee here for additional insights on configuring the jOOQ code generation tool using the Gradle Kotlin DSL. ExecutionGenerating the jOOQ sourcesYou can generate the jOOQ sources for a given jOOQ configuration by invoking the task ./gradlew generateJooq By default, the code generation tasks are automatically configured as dependencies of the corresponding source compilation tasks provided by the Deleting the generated jOOQ sourcesYou can delete the generated jOOQ sources by invoking the task rule ./gradlew cleanGenerateJooq Migration |