Specifying single jar from Project dependency


(Shin Tai) #1

If I have a java project dependency such as:

compile project(":Atest")

and that project produces several jar artefacts (that by default, end up being part of the archives configuration). Is there a way to select a subset of jars from that project only.

I know it sounds daft why I’d want to do this but just trust me on this :slight_smile:

Thanks


(Luke Daley) #2

Project dependencies are actually on configurations. So on the producer side you’ll need to split your artifacts up into different configurations.

On the consumer side, you’ll need to specify what you want…

compile project(path: “:Atest”, configuration: “someStuff”)


(Shin Tai) #3

That did the trick, thanks!

In case it helps anyone, this is what I ended up with on the producer side:

tasks.add(name: "${client.name}Jar", type: Jar) { thisTask ->
   baseName = client.name
   configurations.add(client.name as String)
 artifacts.add(client.name as String, thisTask)
  }

edit: added the task’s output as an artifact instead so that the consumer triggers the build of this configuration as clearly pointed out in the documentation “Project lib dependencies”.