How to publish and reference source code in composite builds?

Our application is split into module projects (GWT modules) and a release project (WAR packaging). Release project needs to run GWT compiler which transforms module Java source code into JavaScript - source code needs to be available on the classpath of compiler.

My initial thinking was to use “sources” classifier to pull in source code of modules for the GWT compiler. This works fine when getting dependencies from repository (each module is published as compiled jar and sources jar). Using the sources classifier however does not work for composite build.

Is there a way to reference source code of dependency that would work both when using repository and composite build?

You should just be able to use “group:artifact:version:classifier” notation.


configurations {
dependencies {
   externalSources "com.mygroup:1.2.3:sources"
tasks.register('gwtCompile', SomeGwtTask) {
   from configurations.externalSources.collect { zipTree(it) } 

That is what I was hoping for but it does not work in composite build. I created project to demo what I struggle with

When you are in the root of the clone and run gradlew :proj2:gwtCompile you get failure

A problem occurred configuring project ‘:proj2’.

Could not create task ‘:proj2:gwtCompile’.
Could not resolve all files for configuration ‘:proj2:externalSources’.
Could not find proj1-sources.jar (project :proj1).

When you CD to the roj2 directory and run gradlew gwtCompile then you get expected error that it was not published yet but the composite should have worked even without artifact published to repository. Also it does not help if the artifact was published.

ok so I found out that someone actually already found workaround for this. Seems like what is required is that the sources jar task is added to the api artifact. I have updated my repo and now it seems to work fine.

I do not really understand why this works but the solution seems acceptable :slight_smile: Can someone explain what is being done with the

artifacts {

I do not really understand why this works

Gradle has separated the process of creating an artifact (eg via Zip or Jar task) from the process of publishing an artifact (via the artifacts {…} closure)

Can someone explain what is being done with the

artifacts {

Ultimately you are adding the artifact to the list of published artifacts for your project under the “api” publication.

Personally I’d do the following to publish the artifact under the more general “archives” publication

artifacts {

See customizing publishing

thank you for the explanation. I guess I’ll need to read up on artifacts, components, variants and what they mean to publishing because I seem to struggle with what’s what there…

I loved the idea of using archives artifact up to a point where it actually did not work :slight_smile: Changing my demo project to archives from api will break it. Is that bug or do I need to do something in relation to the change?