1

I followed this tutorial. This runs fine. I would like to create a multiproject build with one project that contains this spring application. So I added this project to a subfolder called web of this multiproject build, added a settings.gradle file:

include 'web'

As well as a build.gradle file:

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

jar {
  baseName = 'VoPro'
}

dependencies {
  compile project(':web')
}

However, when i run $ gradle build, i get the error:

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

Why can't gradle find any repositories?

EDIT: The web subproject contains the following build.gradle file (like in the tutorial):

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'
}
jvermeulen
  • 505
  • 1
  • 6
  • 14

1 Answers1

2

You should add a build.gradle file under the web project itself and configure appropriate repositories there. Or add a global build.gradle and the following piece of code in it:

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

Basically the multimodule project should have the following structure

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

After discussion in comments: You need to specify the dependency along with version, no idea why:

compile("org.springframework.boot:spring-boot-starter-web:1.2.2.RELEASE")
Opal
  • 81,889
  • 28
  • 189
  • 210
  • I have a build.gradle file in the subproject `web`, sorry if this wasn't clear. It is the exact same as the one in the tutorial. – jvermeulen Mar 08 '15 at 21:11
  • I included this build.gradle file in my question. – jvermeulen Mar 08 '15 at 21:18
  • If I include those repositories i get: `Could not resolve all dependencies for configuration ':runtime'.` `> Could not find org.springframework.boot:spring-boot-starter-web:` `Searched in the following locations:` `.......` – jvermeulen Mar 09 '15 at 08:38
  • Is the project we're talking about online? – Opal Mar 09 '15 at 08:42
  • I have solved the problem by moving the web subproject to the root project (which was empty). This solution seems not as elegant, but it does work. – jvermeulen Mar 14 '15 at 14:53
  • @jvermeulen, thanks. Good to know it. Quite weird this dependency resolution in that case. – Opal Mar 14 '15 at 14:56