Sun
Sun

Reputation: 3564

Grails not picking jars from Maven repository based on pom.xml

I am getting some compilation error because of Grails not picking jars from Maven repository based on pom.xml file.

My BuildConfig.groovy

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
        //excludes "grails-plugin-log4j"
    }

    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    //excludes   "grails-plugin-log4j"
    pom true
    repositories {
        inherits true // Whether to inherit repository definitions from plugins
        //grailsPlugins()
       /// grailsHome()
      //  grailsCentral()

        mavenCentral()
        mavenLocal()

        // These are for the hudson machine
        // mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo"
        // mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo"

        //mavenRepo "http://snapshots.repository.codehaus.org"
        //mavenRepo "http://repository.codehaus.org"
        // mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }

    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
        runtime 'mysql:mysql-connector-java:5.1.5'
                compile 'org.apache.activemq:activemq-core:5.3.0'
        test 'org.objenesis:objenesis:1.2'
        compile 'org.slf4j:slf4j-log4j12:1.6.6'
        //compile "spring-security-config:3.0.1.RELEASE"
    }

    plugins {
        compile ":spring-security-core:1.2.7.3"
        compile ":spring-security-ui:0.2"
        compile ":jquery-ui:1.8.15"
        compile ":jqgrid:3.8.0.1"
        compile ":famfamfam:1.0.1"
        compile ":mail:1.0"
        compile ":jms:1.2"
        compile ":calendar:1.2.1"   
        compile ':gpars:0.3'
        compile ":lang-selector:0.3"
        compile ":crypto:2.0"
        compile ":grails-melody:1.13"
        runtime ":hibernate:$grailsVersion"
        runtime ":jquery:1.7.1"
        //runtime ":resources:1.1.6"
        runtime ":resources:1.2.RC2"
        runtime ":export:1.5"

        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0"
        //runtime ":cached-resources:1.0"
        //runtime ":yui-minify-resources:0.1.4"
         build ":tomcat:$grailsVersion"
         test ":spock:0.6"
    }
}

I am getting error like this:

 Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 141 source files.
| Error Compilation error: startup failed:
/mycompany/dev/rmaddidev/wsmavenTest/pro/src/groovy/com/mycompany/rms/common/RMSExportService.groovy: 15: unable to resolve class org.xhtmlrenderer.pdf.ITextRenderer
 @ line 15, column 1.
   import org.xhtmlrenderer.pdf.ITextRenderer
   ^
1 error

ITextRenderer class exist in core-renderer.jar i specified in maven pom as below.

if i add those jars in BuildConfig.groovy, then it working fine.

 compile 'org.xhtmlrenderer:core-renderer:R8'
    compile 'com.lowagie:itext:2.0.8'

And My Pom file:

<dependencies>
<dependency>
    <groupId>org.xhtmlrenderer</groupId>
    <artifactId>core-renderer</artifactId>
    <version>R8</version>
</dependency>
<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>2.0.8</version>
</dependency>

Upvotes: 2

Views: 3990

Answers (1)

rimero
rimero

Reputation: 2383

You can still use the standard grails commands as long as all your dependencies are referenced in the BuildConfig.groovy.

However, you probably don't want to maintain both the Maven POM and BuildConfig.groovy, unless you have some team members who don't want to use Maven.

Unless the project needs to be 'buildable' using both Maven and the standard Grails command line, avoid the BuildConfig.groovy at all costs, as well as the Grails command line.

Details

When using Maven, you need to do the following :

  • Do not set dependencies in BuildConfig.groovy, add them to your POM:

    • The dependencies block from your BuildConfig.groovy move to the POM(with the default implied type tag set to jar).
    • For non jar dependencies(plugins or non-binary plugins), you need to explicitly set the dependency type to zip in your pom.xml.
  • Also, remove the repositories block from your BuildConfig.groovy, and set the repositories in your POM.

  • Do not use the grails command line, use the Grails Maven goals, as implied by @dmahapatro.


When you decide to use Maven and Grails, it implies that you want avoid having settings in your BuildConfig.groovy.

Then you'd have your build settings(all if it were 100% possible) driven by the Maven POM.

Upvotes: 4

Related Questions