我有多建筑项目,目前我正在设置它。每个模块自然都有一个gradle.build
文件,只包含以下内容:
dependencies {
}
在每个模块都需要我想要的主build.gradle
文件中。但是,当我执行gradle build
时,我收到错误消息:
无法解析外部依赖org.springframework.boot:spring-boot-starter:因为没有存储库 定义。要求: 项目:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
sourceSets.all { ext.purpose = null }
// Everything in subprojects are applied to all modules
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
test {
useTestNG()
testLogging.showStandardStreams = true
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
建议
答案 0 :(得分:5)
您已经为子项目定义了存储库,但您也必须在根项目中定义它,因为那里有dependencies
块:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
在您的情况下,您可以通过repositories
关闭再次声明subprojects
来完成此操作:
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
subprojects {
...
}
或者您可以为所有项目定义它:
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
在这种情况下,你不需要在subprojects
关闭中声明它