Cannot resolve ScalaTest from Gradle
Question
I'm trying to run a simple ScalaTest class with gradle but I keep getting this log from gradle:
* What went wrong:
Could not resolve all dependencies for configuration ':testCompile'.
> Could not download artifact 'org.scala-lang:scala-library:2.10.3@jar'
> Artifact 'org.scala-lang:scala-library:2.10.3@jar' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
I have these dependencies:
dependencies {
compile "io.spray:spray-client:1.2.0"
compile "org.scala-lang:scala-library:2.10.3"
compile "org.scalatest:scalatest_2.10:1.9.1"
}
If I run the task with the --stacktrace
option I get this:
* Exception is:
org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':testCompile'.
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDep
endencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:51)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDep
endencyResolver.access$000(ErrorHandlingArtifactDependencyResolver.java:29)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDep
endencyResolver$ErrorHandlingResolvedConfiguration.getFiles(ErrorHandlingArtifac
tDependencyResolver.java:84)
Basically I'm using the default maven repositores:
repositories {
mavenLocal()
mavenCentral()
}
Solution
There is no 2.10.3 version of scala-library
on Maven Central. The latest I see is 2.10.2-RC2
. That's likely the problem.
EDIT: 2.10.3 is available from Maven Central (I looked in the wrong place). Given the information you provided, I can't say what the problem is, but here is what I'd do:
- To rule out a general networking problem, go to http://central.maven.org/maven2/org/scala-lang/scala-library/2.10.3/ in your browser, and download the Jar manually.
- Make sure you aren't behind a proxy, or configure Gradle accordingly if you are.
- Remove declaration of
mavenLocal()
. - Run
gradle clean build --refresh-dependencies
. - Delete or rename
~/.gradle
, and try again. - If problem persists, run with
--info
,--debug
, or--stacktrace
, and look for hints.
PS: ScalaTest usually goes on the testCompile
configuration.
PPS: mavenLocal()
should only be declared when exchanging artifacts with local Maven builds. It won't save any downloading time or anything. Conversely, it will make the build slower and less repeatable.