grails / grails-gradle-plugin-archived

142 stars 40 forks source link

Posssible resource-loading issue with grails-gradle-plugin for dependent project? #117

Open czellweg opened 10 years ago

czellweg commented 10 years ago

Hey guys

I'm not quite sure whether my issue is on the grails-gradle-plugin side, the grails side, my configuration or a bit of everything so maybe you can help out.

We want to have our js/html resources (Angular) in a separate project (web-js-html) which is a dependee of the main grails app (web-grails). To be specific: we want to refactor out the contents of web-grails/web-app However, when in dev mode, i.e. starting the grails app using 'gradle grails-run-app', the dependent project with those resources doesn't seem to be available on the classpath.

The following are oul build.gradle files:

// web-grails/build.gradle

apply plugin: "grails"

repositories {
    mavenLocal()
    maven { url artifactory_url }
}

buildscript {
    repositories {
        mavenLocal()
        maven { url artifactory_url }
    }
    dependencies {
        classpath 'org.grails:grails-gradle-plugin:2.1.0'
    }
}

grails {
    grailsVersion = '2.3.8'
    groovyVersion = '2.3.0'
}

dependencies {
    bootstrap 'org.grails.plugins:tomcat:7.0.50'
      compile project(':web-js-html')
}

// web-js-html/build.gradle
apply plugin: 'java'

ext {
    webjarconfig = [
            staticHTMLFilesDir : "${projectDir}/src/main/webfrontend",
            baseDir: "META-INF/resources/",
            subDir : "webjars/" + deployed_app_name
    ]
}

jar {
    from(fileTree(webjarconfig.staticHTMLFilesDir)) {
        into webjarconfig.baseDir + webjarconfig.subDir
    }
    outputs.file archivePath
}

In my - maybe naive - understanding, I would assume that the resources in web-js-html will be available on the web-grails classpath. However, this is not the case.

If I package the web-grails app and deploy it to a standalone Tomcat, it works fine as the resources are bundled in a jar under the META-INF/resources which will be available through the servlet 3.0 contrainer, i.e. they're on the classpath.

Could this be an issue of the grails-gradle-plugin or is it an issue on the Grails side?

Thanks in advance for your opinion.

johnrengelman commented 10 years ago

Without digging into it, my guess is that it's something that is not supported by Grails. I say this, because the plugin is not doing anything special here. It is setting up the classpath path and then launching Grails in a separate JVM.

The first thing I would try is to create your JAR file and then create a plain Grails app (without Gradle), add the jar in BuildConfig.groovy to the compile dependencies and see if you can use them in dev mode.

johnrengelman commented 10 years ago

You can also verify your classpaths by adding something like this to your build file:

run { //or 'grails-run-app' depending on which one you're using
  doFirst {
    logClasspaths()
  }
}
czellweg commented 10 years ago

John, thanks for your quick reply.

Logging the classpath reveals that the needed jar is on the runtime classpath (which is what is needed). Seeing that tomcat is used and that I've specified servlet 3.0, I would assume that, at the very least, the resources under META-INF/resources are made available to Grails. That doesn't seem to be the case though.

I might ask the guys from Grails then. Thank you for your help!