Gradle allows adding source dependencies to a build since 4.10. Even though the process is quite simple, I stumbled upon a small problem when using them.
I wanted to add the Lazo library to a Gradle build at work. It follows the requirements for using a source dependency with Gradle:
- uses the Gradle build system
- no published JARs (otherwise it would have been simpler)
Following the documentation
Following the blog post, I did the following:
- updated
settings.gradle
to define a source mapping:
sourceControl {
gitRepository("https://github.com/mitdbg/lazo") {
producesModule("lazo:lazo")
}
}
- added a dependency in
build.gradle
:
dependencies {
implementation("lazo:lazo") {
version {
branch = "master"
}
}
}
- built the project (
./gradlew build
):
...
> Git repository at https://github.com/mitdbg/lazo did not contain a project publishing the specified dependency.
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Nice error message…
Adding the missing property
After some time fiddling with different parameters and trying to understand why Gradle could not resolve the library, it turned out the error was with the Lazo configuration.
Most Java packages follow a convention declared with the following properties:
groupId
artifactId
version
Gradle uses the same scheme, but:
groupId
is just namedgroup
artifactId
is mapped toname
version
has the same name
It turned out that Lazo missed the group
property in its build. Gradle does not take into account empty groups, so I could not use :lazo
to include the library.
The solution was to fork the library on my GitHub account, and just add the group property.
Afterwards, I just had to replace https://github.com/mitdbg/lazo with https://github.com/jfyuen/lazo in settings.gradle
above, and the builds finally succeeded.