Travis Gockel
Travis Gockel

Reputation: 27673

Gradle: Overriding Dependency with Different Name

I am trying to import org.scalatra:scalatra-atmosphere:2.2.0-RC3 into a Scala 2.10 project. The issue is that this package depends on the two non-Scala-versioned packages com.typesafe.akka:akka-actor:2.0.4 and com.typesafe.akka:akka-testkit:2.0.4 (org.scala-lang:scala-library:2.9.2 and org.scalatra:scalatra-json:2.2.0-RC3 should work fine, as they will go to newest). As far as I can tell, the Akka dependencies do not exist on Maven Central, so we have broken packages.

I would like to override org.scalatra:scalatra-atmosphere:2.2.0-RC3's dependencies by hand by replacing the non-Scala-versioned packages with Scala-versioned packages that actually exist:

configurations.all {
    resolutionStrategy {
        eachDependency { details ->
            if (details.requested.group == 'com.typesafe.akka') {
                details.requested.name += "_$scalaVersion"
                details.useVersion '2.1.0'
            }
        }
    }
}

Unfortunately, this technique appears to be explicitly disallowed as of Gradle 1.4:

 What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> new ModuleRevisionId MUST have the same ModuleId as original one. original = com.typesafe.akka#akka-actor new = com.typesafe.akka#akka-actor_2.10

Is there a legitimate way to work around this issue?

Upvotes: 3

Views: 1925

Answers (1)

Matt
Matt

Reputation: 8476

Only version changes are supported in 1.4, 1.5 is due to contain support for changing the other attributes of a dependency.

I think your options are variations on excluding the specific dependency and adding it back in by hand. Examples can be found in the docs

dependencies {
    compile("org.scalatra:scalatra-atmosphere:2.2.0-RC3) {
        exclude group: 'com.typesafe.akka', module: 'akka-actor'
        exclude group: 'com.typesafe.akka', module: 'akka-testkit'
    }
    // assuming you have this available in a repository your build is configured to resolve against
    compile 'com.typesafe.akka:akka-actor:2.0.4-MY.LOCAL.VERSION' 
}

Upvotes: 4

Related Questions