mrt181
mrt181

Reputation: 5316

How to fix this gradle dependency resolution error?

I am new to gradle and I am trying to use it for an existing java project.

I have created settings.gradle file in my root directory:

include ':datamodel'
include ':active'
include ':client'
include ':zero'
include ':toall'

and build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    }
}

The build.gradle in datamodel looks like this:

apply plugin: 'java'
sourceSets {
    main.java.srcDirs = ['src/main/java']
    main.resources.srcDirs = ['src/main/java']
    test.java.srcDirs = ['tests/java']
    test.resources.srcDirs = ['tests/resources']
}

dependencies {
    compile 'com.google.protobuf:protobuf-java:2.5.+'
}

When I run gradle build (version: 2.0) I get this failure

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':datamodel:compile'.
> Could not find any version that matches com.google.protobuf:protobuf-java:2.5.+.
  Required by:
      MyRoot:datamodel:unspecified

How can I fix this?

Upvotes: 4

Views: 24990

Answers (3)

pavlini4
pavlini4

Reputation: 1

You can also try and add jcenter() to dependencies like this

dependencies {
    mavenCentral()
    jcenter()
}

which will allow to search not only in repo1.maven.org

Upvotes: 0

Radim
Radim

Reputation: 4808

Add

repositories {
    mavenCentral()
}

to your build script. Not as a part of buildscript closure where you can define where to look for dependencies required to execute your build script. You can do it in your top-level build.gradle using

allprojects {
    repositories {
        mavenCentral()
    }
}

Upvotes: 3

Prabhakaran Ramaswamy
Prabhakaran Ramaswamy

Reputation: 26094

Try this

compile 'com.google.protobuf:protobuf-java:2.5.0'

More info here

The maven repo looks like

<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>2.5.0</version>
</dependency>

Upvotes: 2

Related Questions