Reputation: 1679
I am trying to setup a simple application with one Java module. There is the parent application and a module called "feature".
Despite the IDE autocompletion working ok I keep getting this error during build:
error: module not found: spring.web
My current setup is:
I have done a dozen other apps using "gradle modules" and I am using the same directory structure:
The parent build.gradle is this:
plugins {
id 'org.springframework.boot' version '2.5.0-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.mrv'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
java {
modularity.inferModulePath = true
}
allprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
}
dependencies {
implementation project(':feature')
}
The "feature" module-info.java (where the problem is occurring) is this:
module com.mrv.modules.feature {
requires spring.web;
}
I based myself on some Maven projects and also the Gradle documentation. I also tried to put my main class ModulesApplication inside its own module with the same results.
Am I missing something?
Upvotes: 1
Views: 356
Reputation: 1679
A couple of hours later I found the solution and it was quite simple: apply modularity.inferModulePath = true to all projects:
plugins {
id 'org.springframework.boot' version '2.5.0-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.mrv'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
/* >>>> MOVED HERE <<<<*/
java {
modularity.inferModulePath = true
}
}
dependencies {
implementation project(':feature')
}
This is a sample project I made to use as a reference in the future.
Upvotes: 1