This Gradle plugin connects to a database and generates Exposed table definitions for all of its tables.
Add plugin declaration into your build script:
plugins {
id("com.jetbrains.exposed.gradle.plugin")
}
Use gradle task as
gradle generateExposedCode
- Using task properties:
gradle generateExposedCode --connectionURL jdbc:postgresql:staff
- Using system variables
gradle generateExposedCode -DconnectionURL=jdbc:postgresql:staff
-
Using environment variables
-
Using project variables
gradle generateExposedCode -PconnectionURL=jdbc:postgresql:staff
- Using a .properties file and specifying its filepath
exposedCodeGeneratorConfig {
propertiesFilename = "exposedPluginProps.properties"
}
exposedPluginProps.properties:
connectionURL=jdbc:postgresql:testone?user=postgres&password=testing
- Using a task configuration in a
build.gradle
file
exposedCodeGeneratorConfig {
databaseDriver = "postgresql"
databaseName = "pltest"
user = "root"
configFilepath = "exposedCodeGeneratorConfig.yml"
}
It is strongly recommended to avoid mixing different ways of specifying parameters.
-
connectionURL
-- connection URL as used with JDBC (e.g.jdbc:postgresql://localhost:12346/user=postgres&password=
) -
Specifying each connection parameter:
databaseDriver
, as used with JDBC (e.g.postgresql
,h2
)databaseName
user
password
host
(IPv4)port
ipv6Host
connectionProperties
- map of properties that will be added toconnectionURL
string
All of those parameters are optional; however, the expected behavior is that the user does not mix a connectionURL
with other parameters.
-
configFilename
-- a path to a.yml
config file -
Specifying each configuration parameter:
packageName
-- the name of the package the generated files belong togenerateSingleFile
-- set totrue
if all tables are to be placed in the same file; otherwise a separate file is created for each table, titled same as table name in camel casegeneratedFileName
-- specify only whengenerateSingleFile = true
; the name of the file to be generated. Default filename isGeneratedTables.kt
collate
-- specify collation method for all string (char
/varchar
/text
) columns in the database (e.g.NOCASE
for SQLite)columnMappings
-- in case the code generator is unable to provide a satisfactory definition for the column, it's possible to provide its definition directly in form of Exposed code (e.g. in order to map certainDouble
columns tofloat
, use the following:mapped_column_table.float_column: float("float_column")
; the column should be addressed as[table_name].[column_name]
)
By default, the generated files are written to build/tables
directory (in case of a single file generation, the filename is GeneratedTables.kt
). The parameter is outputDirectory
and it can be set like all the other ones.
For now, Shadow gradle plugin relocates kotlin classes not so good in a place of reflection. Some class metadata stayed not relocated that brakes the code in runtime.
If you need the proper kotlin class relocation use ShadowJar.kotlinRelocate
function instead of ShadowJar.relocate
.
Don't use kotlinRelocate
on java dependencies as it will add overhead on relocation time without any benefit.
Also, if you plan to relocate Exposed dependencies don't forget to add mergeServiceFiles()
call in your task declaration.
plugins {
id("com.github.johnrengelman.shadow")
id("com.jetbrains.exposed.gradle.plugin")
}
tasks.shadowJar {
mergeServiceFiles()
kotlinRelocate("org.jetbrains.exposed", "my.own.project.exposed")
}
Please note that it's still impossible to relocate kotlin-stdlib itself as it has internal synthetic classes like kotlin.Any
that will not be relocated.