Can a project have a dependency on an artifact created in another project?


(Derek Ealy) #1

I have a multi-project build. In projectA there is a libProjectA.jar that is created, along with a separate prjAAssets.zip artifact.

In projectB I have a dependency to projectA, but it doesn’t seem to be able to find the projectA.zip artifact.

I’ve already tried something like this:

project('prjA')
  configurations { zipAssets }
  ...
  task generateZipAssets(type: Zip) { from fileTree(dir: assets_dir, include: '**/*') }
  artifacts { zipAssets generateZipAssetsTask }

project('prjB')
  dependencies {
    compile project(':prjA')
    runtime project(path: ':prjA', configuration: 'zipAssets') }

However this type of dependency on the other project’s configuration zipAssets doesn’t appear to locate the prjAAssets.zip. Is there a way to make projectB aware of the artifact from projectA, without pushing prjAAssets.zip to an external repository?


(Sterling Greene) #2

Are you sure it’s not working?

This appears to work for me:

subprojects { apply plugin: 'java' }

project('a') {
   configurations { zips }
   task zip(type: Zip) { from "." }
   artifacts { zips zip }
}

project('b') {
   dependencies {
     compile project(':a')
     runtime project(path: ':a', configuration: 'zips')
   }

   task listDeps << { println configurations.runtime.files }
}

Which version of Gradle are you using?


(Derek Ealy) #3

I’m on 2.7, it looks like your’re doing the same thing that I am. :confounded:


(Derek Ealy) #4

So, you’re right it was working all along. I thought that the zip artifact would be on the classpath somewhere. But that isn’t the case. In my java code at runtime I need to be able to find the location of this file and obviously don’t want to hard code it in to the application.

How does Gradle make these artifacts available to the app at runtime?


(Stéphane NICOLAS) #5

And is it possible for a project, to add a configuration to another, as a dependency. Is there a notation to say “self” for the path ? Using the project’s name itself doesn’t work.


(Stéphane NICOLAS) #6

${project.path} works