我有一个多构建项目,我目前只是设置它。每个模块自然都有一个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')
}
建议
您仅定义了子标题的存储库,但是您也必须在root项目中定义它,因为那里有一个dependencies
块:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
在您的情况下,您可以通过再次从subprojects
闭合来宣布repositories
来做到这一点:
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
subprojects {
...
}
,也可以为所有项目定义它:
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
在这种情况下,您不需要o在subprojects
闭合中声明
i在Intellij Idea中使用以下步骤固定。
- 转到设置 - > gradle
- 在'使用'gradle'的下
- gradle jvm我被选为本地java_home