Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin not working in a mono repo Grails app if the dependency is defined in the root build.gradle with a plugin #30

Open
sagrawal31 opened this issue Dec 26, 2022 · 1 comment

Comments

@sagrawal31
Copy link

sagrawal31 commented Dec 26, 2022

Description

I have a mono repo architecture-

| - build.gradle
| - cooee-customer
| - cooee-admin
| - cooee-core         (the plugin)

All the configurations are majorly there in root build.gradle-

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
        classpath "org.grails.plugins:views-gradle:2.3.2"
    }
}

allprojects {
    version "1.5.20"
    group "com.letscooee"
}

ext {
    cooeeGrailsWebApps = ["cooee-customer", "cooee-admin"]
    cooeeGrailsPlugins = ["cooee-core"]
}

subprojects { subProject ->
    boolean isWebApp = cooeeGrailsWebApps.contains(subProject.name)
    boolean isGrailsPlugin = cooeeGrailsPlugins.contains(subProject.name)

    apply plugin: "idea"
    apply plugin: "war"
    apply plugin: "org.grails.plugins.views-json"

    if (isWebApp) {
        apply plugin: "org.grails.grails-web"
    }

    if (isGrailsPlugin) {
        apply plugin: "org.grails.grails-plugin"
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://repo.grails.org/grails/core" }
        maven { url 'https://jitpack.io' }
    }

    configurations {
        developmentOnly
        runtimeClasspath {
            extendsFrom developmentOnly
        }
    }

    dependencies {
        developmentOnly("org.springframework.boot:spring-boot-devtools")
        compileOnly "io.micronaut:micronaut-inject-groovy"
        // https://github.com/grails/grails-embedded-mongodb/issues/30
        //compileOnly "org.grails.plugins:embedded-mongodb:2.0.1"
        console "org.grails:grails-console"
        implementation "org.springframework.boot:spring-boot-starter-logging"
        implementation "org.springframework.boot:spring-boot-starter-validation"
        implementation "org.springframework.boot:spring-boot-autoconfigure"
        implementation "org.grails:grails-core"
        implementation "org.springframework.boot:spring-boot-starter-actuator"
        implementation "org.springframework.boot:spring-boot-starter-tomcat"
        implementation "org.grails:grails-plugin-url-mappings"
        implementation "org.grails:grails-plugin-rest"
        implementation "org.grails:grails-plugin-codecs"
        implementation "org.grails:grails-plugin-interceptors"
        implementation "org.grails:grails-plugin-services"
        implementation "org.grails:grails-plugin-datasource"
        implementation "org.grails:grails-plugin-databinding"
        implementation "org.grails:grails-web-boot"
        implementation "org.grails:grails-logging"
        implementation "org.grails.plugins:cache"
        implementation "org.grails.plugins:async"
        implementation "org.grails.plugins:mongodb"
        implementation "org.grails.plugins:views-json"
        implementation "org.grails.plugins:views-json-templates"
        testImplementation "io.micronaut:micronaut-inject-groovy"
        testImplementation "org.grails:grails-gorm-testing-support"
        testImplementation "org.mockito:mockito-core"
        testImplementation "io.micronaut:micronaut-http-client"
        testImplementation "org.grails:grails-web-testing-support"
        testImplementation "org.grails:views-json-testing-support"
        testImplementation "org.hibernate.validator:hibernate-validator:6.1.7.Final"

        // For LocalConfig and External Config files
        implementation "dk.glasius:external-config:3.1.0"
        implementation "org.redisson:redisson:3.14.1"

        testImplementation "com.github.kstyrc:embedded-redis:0.6"
    }

    if (isGrailsPlugin) {
        dependencies {
            profile "org.grails.profiles:plugin"
            compileOnly "org.grails:grails-plugin-services"
            compileOnly "org.grails:grails-plugin-domain-class"
        }
    }

    if (isWebApp) {
        dependencies {
            profile "org.grails.profiles:rest-api"
            implementation project(":cooee-core")
        }
    }

    bootRun {
        ignoreExitValue true
        jvmArgs(
                '-Dspring.output.ansi.enabled=always',
                '-noverify',
                '-XX:TieredStopAtLevel=1',
                '-Xmx1024m')
        sourceResources sourceSets.main
        String springProfilesActive = 'spring.profiles.active'
        systemProperty springProfilesActive, System.getProperty(springProfilesActive)
    }

    tasks.withType(Test) {
        useJUnitPlatform()
        configure {
            systemProperty "ci", System.getProperty("ci")
        }
    }

    tasks.withType(GroovyCompile) {
        configure(groovyOptions) {
            forkOptions.jvmArgs = ['-Xmx1024m']
        }
    }
}

Problem

When the line api "org.grails.plugins:embedded-mongodb:2.0.1" is in the root build.gradle, and running the command ./gradlew cooee-customer:integrationTest, the test cases never run and ultimately fail with MongoTimeoutException.

Temporary Workaround

I spent hours trying to investigate the root cause without success. Although, I was able to fix my test cases by moving it to cooee-core/build.gradle.

Environment

grailsVersion=5.2.5
grailsGradlePluginVersion=5.2.4
groovyVersion=3.0.11
gorm.version=7.3.2
  • macOS Ventura
  • java 11.0.15 2022-04-19 LTS
@sagrawal31
Copy link
Author

My two cents- When the dependency is defined in root build.gradle, since it's also used by cooee-core, it's doWithSpring is being executed twice, one for cooee-customer and one for cooee-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant