【问题标题】:gradle: migrate spring app to a multiproject buildgradle:将 spring 应用程序迁移到多项目构建
【发布时间】:2015-03-08 15:22:40
【问题描述】:

我关注了这个tutorial。这运行良好。 我想用一个包含这个 spring 应用程序的项目创建一个多项目构建。所以我将此项目添加到此多项目构建的名为web 的子文件夹中,添加了一个 settings.gradle 文件:

include 'web'

还有一个 build.gradle 文件:

apply plugin: 'application'
mainClassName = "hello.Application"

jar {
  baseName = 'VoPro'
}

dependencies {
  compile project(':web')
}

但是,当我运行 $ gradle build 时,我得到了错误:

Could not resolve all dependencies for configuration ':runtime'.
> Cannot resolve external dependency org.springframework.boot:spring-boot-starter-web: because no repositories are defined.
  Required by:
      :test:unspecified > test:web:unspecified

为什么 gradle 找不到任何仓库?

编辑:web 子项目包含以下 build.gradle 文件(如教程中所示):

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

【问题讨论】:

  • 试试include ':web'
  • @BorisBera 你的意思是在设置文件中?刚试了一下,好像都还好。
  • 我注意到我链接了错误的教程,现在应该修复了

标签: java spring gradle multi-project


【解决方案1】:

您应该在 web 项目本身下添加一个build.gradle 文件并在那里配置适当的存储库。或者添加一个 global build.gradle 并在其中添加以下代码:

allprojects {
   repositories {
      mavenCentral()
      mavenLocal()
   }
}

基本上多模块项目应该有以下结构

-- build.gradle // all projects configuration
-- settings.gradle //includes all modules 
-- module1
  -- build.gradle
-- module2
  -- build.gradle
-- modulen
  -- build.gradle
..

在 cmets 讨论后: 您需要指定依赖项以及版本,不知道为什么:

compile("org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE")

【讨论】:

  • 我在子项目web 中有一个build.gradle 文件,如果不清楚,请见谅。它与教程中的完全相同。
  • 我在我的问题中包含了这个 build.gradle 文件。
  • 如果我包含我得到的那些存储库:Could not resolve all dependencies for configuration ':runtime'.> Could not find org.springframework.boot:spring-boot-starter-web:Searched in the following locations:.......
  • 我们说的项目是在线的吗?
  • 我已经通过将 web 子项目移动到根项目(它是空的)解决了这个问题。这个解决方案看起来不那么优雅,但确实有效。
猜你喜欢
  • 2019-02-11
  • 1970-01-01
  • 2020-01-19
  • 2017-04-06
  • 1970-01-01
  • 2019-06-26
  • 2020-02-05
  • 2020-04-13
  • 1970-01-01
相关资源
最近更新 更多