Depend on a Jar made by a composite project

It seems that I haven’t fully understood the gradle composite build feature. What I would like to is that my main project depends on the jar that is the result of a build of a composite gradle project.

It is nearly the same as to depend on the jar of a subproject. I’m doing this already, and without any problems. The dependency (in the dependencies section of the main project) has to be like

api(project("splitjars", "jnrchannels"))

In this case, the main project build depends on the jars associated with the configuration ‘jnrchannels’ of the subproject ‘splitjars’. Cool. No problems with this.

The composite documentation says that I can depend on a task of the composite by:

tasks.named("compileJava") {
    dependsOn(gradle.includedBuild("jingtrang").task(":build"))
}

Ok. And that I could do a dependency substitution that binds my dependency to the composite (in the main settings.gradle.kts):

includeBuild("submodules/jing-trang") {
    dependencySubstitution {
        substitute(module("com.thaiopensource:jingtrang")).with(project(":"))
    }
}

All right. Now I use the following dependency (in the main project dependencies section):

api("com.thaiopensource ","jingtrang", "")

Well. This kind of works. But only if I had build the composite project in advance. When I start a completely ‘clean’ build, I get the following error:

* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find com.thaiopensource :jingtrang:.
  Searched in the following locations:
    - file:/home/tpasch/scm/db-toolchain/submodules/jing-trang/build/libs/jingtrang.jar
    ...
  Required by:
      project :

This comes with no surprise. On a clean build, the composite build result ‘jingtrang.jar’ has not yet been produced by gradle but it is needed by the configuration phase of the main project. Boomer!

How can I avoid the problem?

1 Like