How to use jOOQ code generation with Gradle? - gradle

I am reading this tutorial of jOOQ
It shows me how I can use jOOQ code-generation from inside Gradle.
Based on this tutorial I modified my build.gradle file and it looks like this:
group 'com.abhi'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.flywaydb.flyway'
sourceCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'com.h2database:h2:1.4.177'
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
}
flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
}
But the part I am not able to understand is that the tutorial also provides some code:
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('jdbc:h2:~/test-gradle')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('org.jooq.example.gradle.db')
directory('src/main/java')
}
}
}
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
Where should I put this code and how shall I execute it?
This code looks like Groovy code but I am writing a Java project. So how and where does this fit into my project?
My objective is that every time I build the project, all the code generation is done by Gradle itself so that I don't have to run any tools manually.
Does it mean that I copy and paste this code inside of my build.gradle file?

You can e.g. add generate task that will be defined as follows:
task generate << {
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('jdbc:h2:~/test-gradle')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('org.jooq.example.gradle.db')
directory('src/main/java')
}
}
}
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
}

You can create a task and use the org.jooq.meta.jaxb.Configuration class to configure code generation:
In your build.gradle file, you will want to place the following on the very top of the file (this will allow you to use the jOOQ classes (such as the org.jooq.meta.jaxb.Configuration class inside your Gradle file).
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.jooq', name: 'jooq', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-meta', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-codegen', version: '3.13.4'
classpath group: 'org.postgresql', name: 'postgresql', version: '42.2.16'
}
}
Next, create a new file (you can also do it inside build.gradle, but I like to separate it for better organization) called jooq.gradle, or whatever you would like to call it.
The following file is adapted from here with some minor modifications.
At the top of your program, you will want to add the following imports that will let us work with jOOQ (they may show up as red or invalid, but we'll fix that in just a bit):
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.Database
import org.jooq.meta.jaxb.Generator
import org.jooq.meta.jaxb.Jdbc
import org.jooq.meta.jaxb.Target
Great!, now we can define some variables after this for better organization (not required):
ext.db = [
url: 'jdbc:postgresql://localhost:5432/postgres',
user: 'postgres',
password: 'postgres',
schema: 'public',
driver: 'org.postgresql.Driver',
jooqDbImpl: 'org.jooq.meta.postgres.PostgresDatabase',
packageName: 'samplepackage'
]
ext.genpath = new File("${projectDir}/build/generated-src/jooq/main")
For the above snippet, you will want to change the variables according to your configuration.
Next, we can add our buildscript again for this file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.jooq', name: 'jooq', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-meta', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-codegen', version: '3.13.4'
classpath group: 'org.postgresql', name: 'postgresql', version: '42.2.16'
}
}
After this, we can add genPath as a Java source file:
sourceSets.main.java.srcDirs += genpath.toString()
And we can finally start our generateCode() task!
Create the function definition as such:
task generateCode() {
}
Inside you will want to put this snippet of code, which will configure the generator. Feel free to modify this according to your needs, but I will be putting a snippet that works for me:
org.jooq.meta.jaxb.Configuration configuration = new
org.jooq.meta.jaxb.Configuration()
.withJdbc(new Jdbc()
.withDriver(db.driver)
.withUrl(db.url)
.withUser(db.user)
.withPassword(db.password)
)
.withGenerator(new Generator()
.withDatabase(new Database()
.withName(db.jooqDbImpl)
.withIncludes(".*")
.withExcludes("")
.withInputSchema(db.schema)
)
.withTarget(new Target()
.withPackageName(db.packageName)
.withDirectory(genpath.toString())
)
);
Finally, after all the hard work, you can execute this function, which will create your code using the configuration above:
GenerationTool.generate(configuration);
If you would like to have a function to delete the generated code, you can use the following snippet:
task deleteGeneratedCode(type: Delete) {
delete genpath
}
And here is the following, completed jooq.gradle file:
import org.jooq.codegen.GenerationTool
import org.jooq.meta.jaxb.Database
import org.jooq.meta.jaxb.Generator
import org.jooq.meta.jaxb.Jdbc
import org.jooq.meta.jaxb.Target
ext.db = [
url: 'jdbc:postgresql://localhost:5432/postgres',
user: 'postgres',
password: 'postgres',
schema: 'limehrm',
driver: 'org.postgresql.Driver',
jooqDbImpl: 'org.jooq.meta.postgres.PostgresDatabase'
packageName: 'limehrm'
]
ext.genpath = new File("${projectDir}/build/generated/source/jooq/main")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.jooq', name: 'jooq', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-meta', version: '3.13.4'
classpath group: 'org.jooq', name: 'jooq-codegen', version: '3.13.4'
classpath group: 'org.postgresql', name: 'postgresql', version: '42.2.16'
}
}
sourceSets.main.java.srcDirs += genpath.toString()
task generateCode() {
if (!genpath.exists()) {
genpath.mkdirs()
}
org.jooq.meta.jaxb.Configuration configuration = new
org.jooq.meta.jaxb.Configuration()
.withJdbc(new Jdbc()
.withDriver(db.driver)
.withUrl(db.url)
.withUser(db.user)
.withPassword(db.password)
)
.withGenerator(new Generator()
.withDatabase(new Database()
.withName(db.jooqDbImpl)
.withIncludes(".*")
.withExcludes("")
.withInputSchema(db.schema)
)
.withTarget(new Target()
.withPackageName(db.packageName)
.withDirectory(genpath.toString())
)
);
GenerationTool.generate(configuration);
}
task deleteGeneratedCode(type: Delete) {
delete genpath
}

#Opal's answer works great (thanks!) with a couple of tweaks. Thought I'd share to spare anyone the hassle with newer versions of jOOQ & Gradle.
The changes:
<< removed from the first line and doLast added.
jOOQ .xsd updated to 3.9.2
org.jooq.util.GenerationTool.generate(writer.toString()) to generate the code
task generate {
doLast {
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.9.2.xsd') {
jdbc() {
driver('org.h2.Driver')
url('jdbc:h2:~/test-gradle')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('org.jooq.example.gradle.db')
directory('src/main/java')
}
}
}
org.jooq.util.GenerationTool.generate(writer.toString())
}
}

Related

Why SpotBugs Gradle plugin always generate XML report instead of HTML?

I am using Gradle 5.2, spotbugs-gradle-plugin version 2.0.0 and tried to generate SpotBugs report on my project. I used the following configuration on my project but it always create XML reports instead of html report.
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:+'
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0"
}
}
allprojects {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.github.spotbugs'
group = 'com.myproject'
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
compile('com.google.cloud:google-cloud-storage:+') {
exclude group: "com.google.guava", module: "guava"
}
compile group: 'org.apache.commons', name: 'commons-collections4', version: '+'
compile group: 'com.google.guava', name: 'guava', version: '+'
testImplementation('org.junit.jupiter:junit-jupiter:+')
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
}
project(':myproject') {
dependencies {
compile group: 'com.github.javafaker', name: 'javafaker', version: '+'
compile group: 'org.jsonschema2pojo', name: 'jsonschema2pojo-core', version: '+'
compile group: 'commons-lang', name: 'commons-lang', version: '+'
compile group: 'org.mongodb', name: 'bson', version: '+'
}
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
spotbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
What I did wrong here?
Kindly provide your inputs to create HTML report instead of XML!

gradlew complie has no lib.jar

I am using gradle(Gradle 4.7) to compile a project(Java 1.8) has multimodule:
./gradlew -p web -x test build
and one of it has no dist jar,the others has,what's the problem?the normal dir structure of compile output:
--build
----classes
----libs
----tmp
and the abnormal dir structure:
--build
----classes
----tmp
This is the build.gradle(abnormal module):
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
PS: all module does not generate libs folder,the libs is cache.Why the module does not generate dis jar file,How to configure my gradle project.This is the full config of my project:
group 'dolphin'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
springVersion = '4.3.7.RELEASE'
springfoxVersion = '2.6.1'
jacksonVersion = '2.8.7'
lombokVersion = '1.16.14'
}
ext['tomcat.version'] = '9.0.16'
repositories {
mavenCentral()
jcenter{
url 'http://jcenter.bintray.com'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
def getVersionCode() {
def versionFile = file("$rootDir/version.properties")
if (!versionFile.canRead()) {
throw new GradleException("Could not find version.properties!")
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def versionCode = versionProps['VERSION'].toString()
return versionCode
}
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.7'
}
project(":common") {
description = ''
dependencies {
api("org.springframework:spring-context:" + springVersion)
api("commons-codec:commons-codec:1.10")
api("org.apache.tomcat:tomcat-juli:" + property('tomcat.version'))
api 'org.springframework.boot:spring-boot-starter-web'
api group: 'io.swagger', name: 'swagger-annotations', version: '1.5.20'
api("org.projectlombok:lombok:${lombokVersion}")
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
api group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.0'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.4'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
}
}
project(":composite") {
description = 'dolphin-composite'
dependencies {
implementation project(":monitor-business")
api project(":data")
implementation("org.springframework:spring-context:" + springVersion)
}
}
project(":web") {
description = "web"
archivesBaseName = "dolphin-web-" + getVersionCode()
jar {
// Will include every single one of your dependencies, project or not
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
api project(':monitor-business')
api project(':api')
api project(':common')
api project(':data')
api project(':composite')
implementation("com.zaxxer:HikariCP:2.6.0")
api("org.mybatis:mybatis-spring:1.3.0")
implementation("mysql:mysql-connector-java:5.1.24")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter")
implementation("io.springfox:springfox-swagger2:2.9.2")
implementation("io.springfox:springfox-swagger-ui:2.9.2")
implementation group: 'org.apache.tomcat', name: 'tomcat-juli', version: property('tomcat.version')
implementation("org.projectlombok:lombok:1.16.14")
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
implementation group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
implementation group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
project(":data") {
description = "data"
dependencies {
api project(':common')
api("org.projectlombok:lombok:${lombokVersion}")
implementation("com.zaxxer:HikariCP:2.6.0")
implementation group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
api("org.hibernate:hibernate-validator:5.2.4.Final")
api("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1")
api("org.apache.commons:commons-lang3:3.5")
api group: 'org.springframework', name: 'spring-jdbc', version: '5.1.5.RELEASE'
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
}
}
PS:My problem is like this memo: https://discuss.gradle.org/t/gradle-4-x-jar-is-not-generated/24773
I have solved it but don't know why....
To solve the problem,using this command to build the project(It will generate the libs folder and jar file):
./gradlew -p web -x test -x jar build
Gradle version:4.7.(Gradle 5.3 not work)

Create a jar with external dependencies using Gradle

I have added following in my build.gradle file.
jar {
doFirst {
into('lib') {
from configurations.runtime
}
}}
When I run "gradle build" it creates a JAR file containing all the dependent JARs. But, then it puts that JAR into a ZIP file containing the dependent jars in lib folder again. This ZIP file structure looks like this:
-- 4.11-SNAPSHOT.jar
---- lib
----- lib/dependent1.jar
----- lib/dependent2.jar
-- lib
---- dependent1.jar
---- dependent2.jar
I don't want the ZIP to be generated. I only want the single JAR containing all the dependencies to get generated.
-- 4.11-SNAPSHOT.jar
---- lib
----- lib/dependent1.jar
----- lib/dependent2.jar
Complete build.gradle is below:
repositories {
maven {
url 'https://repository.cloudera.com/content/repositories/releases/'
}
maven {
url 'https://repository.cloudera.com/content/repositories/third-party/'
}
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'com.company.projectname', name: 'domain', version: pppVersion
compile group: 'com.company.projectname', name: 'model', version: modelVersion
compile group: 'com.company.projectname', name: 'pipeline-util', version: pppVersion
compile group: 'com.cloudera.crunch', name: 'crunch', version: '0.3.0-3-cdh-5.2.1'
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.5.0-cdh5.3.3'
compile group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-common', version: '2.5.0-cdh5.3.3'
compile group: 'ch.hsr', name: 'geohash', version: '1.3.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
jar {
manifest {
attributes 'Main-Class': 'com.company.projectname.delta.DeltaClusterer'
}
classifier 'job'
doFirst {
into('lib') {
from configurations.runtime
}
}
}
There is a parent build.gradle as well. And it is as follows:
/**
* Dependencies for build script plugins. Project dependencies should
* be added further in this file.
*/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:2.2.0'
classpath 'org.hidetake:gradle-ssh-plugin:1.0.4'
classpath 'be.xvrt:release-plugin:0.5.1'
}
}
task wrapper( type: Wrapper ) {
gradleVersion = '2.2'
}
// Release script for automated version management.
// Apply at root so it uses/updates the root gradle.properties file.
apply plugin: 'be.xvrt.release'
subprojects {
apply plugin: 'java' // Support for Java.
apply plugin: 'maven-publish' // Upload artifacts to Nexus.
apply plugin: 'be.xvrt.release' // Release script for automated version management.
apply plugin: 'org.hidetake.ssh' // Execute SSH commands.
apply plugin: 'rpm' // Builds RPM artifacts.
apply plugin: 'sonar-runner' // Creates Sonar reports.
apply plugin: 'project-report' // Creates a dependency report, very useful for finding dependency conflicts.
/**
* Global configuration.
*/
sourceCompatibility = 1.6
targetCompatibility = 1.6
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
/**
* Global dependency settings for all projects. Per project dependencies
* should be added to the build.gradle file in every project.
*/
// Common dependencies for all projects.
dependencies {
// Also see resolutionStrategy below when modifying semantic-TTOM-ddct version!
compile group: 'com.teleatlas.models', name: 'semantic-TTOM-ddct', version: '4.0.2.0'
compile group: 'com.google.guava', name: 'guava', version: '15.0'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'args4j', name: 'args4j', version: '2.0.29'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.8'
}
// The install artifact is only required for command line applications.
if ( !tasks.findByPath( 'war' ) ) {
task buildInstallZip( type: Zip ) {
from jar.outputs.files
// Copy all dependencies into lib.
into( 'lib' ) {
from configurations.runtime.allArtifacts.files
from configurations.runtime
}
}
}
/**
* Publish to Nexus.
*/
artifacts {
archives buildSourcesJar
archives buildJavadocJar
if ( !tasks.findByPath( 'war' ) ) {
archives buildInstallZip
}
}
publishing {
publications {
maven( MavenPublication ) {
if ( tasks.findByPath( 'war' ) ) {
from components.web
}
else {
from components.java
}
artifact buildSourcesJar {
classifier 'sources'
}
artifact buildJavadocJar {
classifier 'javadoc'
}
if ( !tasks.findByPath( 'war' ) ) {
artifact buildInstallZip {
classifier 'install'
}
}
}
}
}
}
/**
* Build RPM artifacts for command line applications.
*/
configure( [project( ':project1' ),
project( ':project2' ),
project( ':project3' )] ) {
task rpm( type: Rpm, dependsOn: 'jar' ) {
if ( version.contains( 'SNAPSHOT' ) ) {
logger.info( 'Building SNAPSHOT RPM.' )
version project.version.replace( '-SNAPSHOT', ".${System.currentTimeMillis()}" )
}
else {
logger.info( 'Building RELEASE RPM.' )
version project.version
release '1'
}
vendor 'company'
packageGroup 'company'
permissionGroup "Applications/${project.name}"
arch NOARCH
os LINUX
into '/usr/share/java/'
from( jar.outputs.files ) {
into project.name
}
from( configurations.runtime ) {
into "${project.name}/lib"
}
}
// When publishing artifacts, the rpm is also published (and created).
publish.dependsOn publishRpm
publishRpm.dependsOn rpm
}
What needs to be done for this?
I'm guessing the problem is the buildInstallZip task you have defined in the parent build.gradle file. It looks like that task is duplicating the functionality yo're now adding to the jar task in the subproject.
Did you write the parent build file, or was that provided by someone else? Maybe 2 people are both trying to solve the same problem in 2 different ways?
Anyway, to solve, either disable the buildInstallZip task in that subproject, or remove your modifications from the jar task and instead use the zip produced by buildInstallZip as you application distribution.

Gradle Plugin Execution Order

I have written this gradle file
group 'com.abhi'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.flywaydb.flyway'
sourceCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'com.h2database:h2:1.4.177'
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
}
flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
}
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('dbc:h2:file:target/foobar')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('com.abhi.jooq.models')
directory('src/main/java')
}
}
}
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
when I say gradle compile it throws an exception
Could not load schemata
java.lang.NullPointerException
at org.jooq.impl.MetaImpl.meta(MetaImpl.java:120)
at org.jooq.impl.MetaImpl.getCatalogs(MetaImpl.java:143)
at org.jooq.impl.MetaImpl.getSchemas(MetaImpl.java:168)
at org.jooq.util.jdbc.JDBCDatabase.getSchemasFromMeta(JDBCDatabase.java:135)
at org.jooq.util.jdbc.JDBCDatabase.getSchemata0(JDBCDatabase.java:124)
at org.jooq.util.AbstractDatabase.getSchemata(AbstractDatabase.java:279)
I think the problem is that the code at the bottom of the script executes much before the "flyway" plugin.
Is there a way I can ensure that the code below is executed only after the flyway plugin has executed?
Yes, if you suppose, the problem is in execution order, then you can modify it, just like with any other tasks. Take a look at the documentation of the flyway plugin. According to it, this plugin adds some extra tasks to your build script, for thos one tasks are: flywayMigrate, flywayClean etc. You can make any of your tasks depending (with dependsOn option) on the tasks form this plugin and make them running just after the plugin's job is done.

tasks.setupAll.dependsOn(copyJars) does not work in gradle?

I tried following the answer here
how to override a task making it depend on one of mine in gradle
but it fails with
Could not find property 'setupAll' on task set.
I have tried a few things
Make the task in subprojects section depend on master:copyJars but that fails
The below solution
stripped off the tasks which didn't work.
I have only ONE build.gradle file and the settings.gradle file. The settings gradle file is
include 'master', 'toneserver','webserver'
The master build.gradle file is(SPECIFICALLY, search for the two instances of setupAll as somehow there is something wrong with that)
//NOTE: Currently this file is for dependency management only but we would like
// to convert all of the build to gradle from the ant files. We needed to add dependency
// management so did so with gradle first as a first step in the process of evolution
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
buildDir = 'output'
task hello << { task -> println "I'm $task.project.name" }
build << { task -> println "MASTER: I'm building now classpath=$sourceSets.main.compileClasspath.files" }
}
project(':toneserver') {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
compile project(':master')
compile project(':webserver')
}
task eclipse(overwrite: true) {
}
}
project(':webserver') {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
compile project(':master')
}
//playframework has it's own generation of .classpath and .project fils so do not
//overwrite their versions
task eclipse(overwrite: true) {
}
}
project(':master') {
project.ext.genLibDir = file('lib')
project.ext.fixedLibDir = file('libother')
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.1.4.Final'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.6.6'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.0.6'
compile group: 'joda-time', name: 'joda-time', version: '2.1'
compile group: 'com.google.inject',name: 'guice', version: '3.0'
compile group: 'com.google.protobuf',name: 'protobuf-java', version: '2.4.1'
//to be erased soon
compile group: 'commons-configuration',name:'commons-configuration',version: '1.8'
compile group: 'org.jboss.netty', name: 'netty', version: '3.2.7.Final'
//compile group: 'org.asteriskjava',name: 'asterisk-java', version: '1.0.0.M3'
compile fileTree(dir: project.ext.fixedLibDir, include: '*.jar')
}
task('copyJars') {
ext.collection = files { genLibDir.listFiles() }
delete ext.collection
copy { from configurations.compile into genLibDir }
copy { from fixedLibDir into genLibDir }
}
tasks.setupAll.dependsOn(copyJars)
}
subprojects {
version = 'Developer-Build'
//configurations.compile {
// exclude group: 'javax.jms', module: 'jms'
// exclude group: 'com.sun.jdmk', module: 'jmxtools'
// exclude group: 'com.sun.jmx', module: 'jmxri'
//}
task('setupAll', dependsOn: ['eclipse']) {
description = 'Update jars from remote repositories and then fix eclipse classpath for master project'
}
hello << {println "- I depend on stserver"}
build << { println "subproject:source sets=$sourceSets.main.java.srcDirs" }
}
task release << { println "putting together release" }
//TODO: have a release task AND if version is null when running the release task
//throw an exception telling the user to pass in a version with "./build -Dversion=xxxx"
//The automated build will call the release task with a version number like that
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release) && version == 'Developer-Build') {
throw new StopExecutionException("You must specify -Dversion=<some version> to run the release task")
} else {
version = '1.0-SNAPSHOT'
}
}
What is going on with this? Overriding tasks to depend on other stuff should work pretty easily I though(maybe that syntax is still wrong?)
thanks,
Dean
never mind, stupid mistake, forgot my task was in subprojects and should be outside and needed a : as well so new setupAll is outside subprojects and is
task('setupAll', dependsOn: [':master:copyJars', 'eclipse']) {
description = 'Update jars from remote repositories and then fix eclipse classpath for master project'
}

Resources