0

I am setting up a project which will have multiple microservices. Each microservice will need to use the flyway (org.flywaydb.flyway) and jooq (nu.studer.jooq) plugins to migrate alter scripts and generate kotlin files for records and tables at compile time.

I started off with defining the plugins and their configs in the build.gradle for each microservice and that works. So my configuration is correct. Now I would like to put this configuration in a separate gradle file to be able to reuse it from all the microservices.

I managed to put the configs for jooq and flyway in a separate file called jooq.gradle but I still have to define the plugins in the microservices.

This is my build.gradle for a microservice:

buildscript {
    dependencies {
        classpath "org.flywaydb:flyway-mysql:$flyway_version"
        classpath "mysql:mysql-connector-java:$mysql_connector_version"
    }
}
plugins {
    id "org.flywaydb.flyway" version "$flyway_version"
    id 'nu.studer.jooq' version '7.1.1'
}
apply from: "$rootDir/gradle/common.gradle"
apply from: "$rootDir/gradle/jooq.gradle"

// Other dependencies of the individual microservice

This is my jooq.gradle which the microservices use.

apply from: "$rootDir/gradle/common.gradle"

dependencies {
    api "org.jooq:jooq:$jooq_version"
    jooqGenerator "mysql:mysql-connector-java:$mysql_connector_version"
}

flyway {
    // Flyway Config Here
}

jooq {
    // Jooq Config here
}

Is it possible to put the following part from build.gradle in my common jooq.gradle file as well?

buildscript {
    dependencies {
        classpath "org.flywaydb:flyway-mysql:$flyway_version"
        classpath "mysql:mysql-connector-java:$mysql_connector_version"
    }
}
plugins {
    id "org.flywaydb.flyway" version "$flyway_version"
    id 'nu.studer.jooq' version '7.1.1'
}

I tried putting the following in my jooq.gradle file but I still required had to define the buildscript and plugins blocks in my build.gradle so it is useless.

buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath "mysql:mysql-connector-java:$mysql_connector_version"
        classpath "org.flywaydb:flyway-mysql:$flyway_version"
        classpath("gradle.plugin.org.flywaydb:gradle-plugin-publishing:$flyway_version")
        classpath("nu.studer:gradle-jooq-plugin:7.1.1")
    }
}
apply plugin: "org.flywaydb.flyway"
apply plugin: "nu.studer.jooq"

0 Answers0