我是gradle的新手,我正在尝试将它用于现有的java项目。
我在根目录中创建了settings.gradle文件:
include ':datamodel'
include ':active'
include ':client'
include ':zero'
include ':toall'
和build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
datamodel中的build.gradle如下所示:
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.+'
}
当我运行gradle build(版本:2.0)时,我得到了这个失败
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
我该如何解决这个问题?
答案 0 :(得分:2)
试试这个
compile 'com.google.protobuf:protobuf-java:2.5.0'
更多信息here
maven repo看起来像
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
答案 1 :(得分:2)
添加
repositories {
mavenCentral()
}
到你的构建脚本。不作为buildscript
闭包的一部分,您可以在其中定义查找执行构建脚本所需的依赖项的位置。您可以使用
build.gradle
中执行此操作
allprojects {
repositories {
mavenCentral()
}
}
答案 2 :(得分:0)
您还可以尝试将jcenter()
添加到此类
dependencies {
mavenCentral()
jcenter()
}
,不仅可以在repo1.maven.org