I have the following project strucuture:
example
├── build.gradle
├── module1
│ ├── build.gradle
│ └── main
│ ├── java
│ │ ├── module-info.java
│ │ └── com.example.module1
│ │ └── Example.java
│ └── resources
│ └── application.yml
└── module2
├── build.gradle
├── main
│ ├── java
│ │ ├── module-info.java
│ │ └── com.example.module2
│ │ └── Example2.java
└── test
build.gradle
repositories {
maven {
url 'http://download.osgeo.org/webdav/geotools/'
name 'Open Source Geospatial Foundation Repository'
}
maven {
url 'https://repo.boundlessgeo.com/main/'
name 'Boundless Maven Repository'
}
maven {
url 'http://repo.boundlessgeo.com/snapshot'
name 'Geotools SNAPSHOT repository'
mavenContent {
snapshotsOnly()
}
}
mavenCentral()
jcenter()
}
dependencies {
implementation "org.geotools:gt-main:$geotoolsVersion"
}
build.gradle
(depends on module1)repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation project(':module1')
}
The problem is that when resolving the dependencies for module2
, it is unable to find the transitive dependencies of module1
, and so I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':module2'.
> Could not resolve all files for configuration ':module2:runtimeClasspath'.
> Could not find org.geotools:gt-main:21.2.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/geotools/gt-main/21.2/gt-main-21.2.pom
- https://repo.maven.apache.org/maven2/org/geotools/gt-main/21.2/gt-main-21.2.jar
- https://jcenter.bintray.com/org/geotools/gt-main/21.2/gt-main-21.2.pom
- https://jcenter.bintray.com/org/geotools/gt-main/21.2/gt-main-21.2.jar
Required by:
project :module2 > project :module1
It looks like it is only searching for the transitive deps of module1
using the repositories declared in module2
instead of in module1
.
Interestingly, if I change the dependency in module2
to:
dependencies {
compileClasspath project(':module1')
}
The dependencies are resolved. However this means that at runtime, module1
is not part of the classpath, so running the application still fails.
How can I fix this?
The problem is that project dependencies do not leak their repository locations when depended on.
The fix is to move the repositories into the root build.gradle
. Something like:
subprojects {
repositories {
//https://docs.geotools.org/latest/userguide/build/maven/repositories.html
maven {
url 'http://download.osgeo.org/webdav/geotools/'
name 'Open Source Geospatial Foundation Repository'
}
maven {
url 'https://repo.boundlessgeo.com/main/'
name 'Boundless Maven Repository'
}
}
}
See the following github issues: