David Seiler
David Seiler

Reputation: 9705

How do I get grails 2.4.3 to resolve dependencies in <project-dir>/lib?

I have a Grails 2.2.4 project which I'm upgrading to Grails 2.4.3. I've mostly navigated the dependency changes, I think, except that none of our local jars resolve anymore.

Specifically, our project depends on several jars in our lib directory--for example, newrelic-api-2.18.0.jar. Whenever I try to compile the project, I get this error:

| Error Resolve error obtaining dependencies: The following artifacts could not be resolved:  newrelic:newrelic-api:jar:2.18.0  in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)

...which is completely fair as far as it goes: that jar really isn't in grailsCentral, it's in my-project/lib. So how do I get Grails to look for it there?

All of our local dependencies fail to resolve this way. All of our remote dependencies resolve correctly (at least, they did once I made a few small changes to e.g. the Hibernate version). I can get dependency resolution to succeed by commenting out all the local dependencies, but of course then compilation falls over a bit later with a bunch of NoClassDefFoundErrors.

When I switch back to 2.2.4, everything is fine again: the dependency is correct resolved and the app loads without a problem.

Here's the head of my buildConfig:

grails.servlet.version = "2.5"
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6

grails.project.dependency.resolver = "maven"

grails.project.dependency.resolution = {
    cacheDir "target/ivy-cache"
    inherits("global") { }
    log "warn"
    checksums true
    legacyResolve true // whether to do a secondary resolve on plugin installation, not advised and here only for backwards compatibility

    repositories {
        inherits true

        grailsPlugins()
        grailsHome()
        grailsCentral()
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        runtime 'newrelic:newrelic-api:2.18.0'
        // ...various other deps, plugins, and whatnot...
    }
}

What am I doing wrong? I don't see any discussion of this problem in the release notes, so it surely can't be an expected consequence of all the dependency changes.

Upvotes: 3

Views: 1061

Answers (1)

David Seiler
David Seiler

Reputation: 9705

This turns out to be a known issue, sort of; see the "No initial offline mode with Aether" section in the upgrade guide. The guide only mentions the jars that ship with grails, but all jars are affected and no jar is ever resolved locally unless it has first been resolved remotely. I guess if you have local dependencies, you're supposed to serve them from a Maven install of your own.

If for some reason you do not wish to manage your own Maven repo, the upgrade guide recommends that you use Ivy instead. DO NOT DO THIS. Ivy does not resolve transitive dependencies reliably in 2.4.3. If you can't maintain your own Maven repo, do not upgrade.

Upvotes: 1

Related Questions