How to publish specific sourceset JAR to Maven


(Matt Painter) #1

Hi,

My Java project has two source sets - ‘main’ and ‘generated’ - and I am wishing to publish the jar created by Gradle for the generated source set to a Maven repository.

How can one do this elegantly? Does the Maven plugin know about source sets?

Using generic settings as obtained from Chapter 46, the ‘uploadArchives’ task is attempting to upload the project’s war file, which isn’t what I’m after. Example 46.6.2 only covers publishing the default jar file and I can’t see an example in that chapter for being able to explicitly specify a file to upload.

Apologies if this is a dumb question; this is my first real foray into Gradle after coming from an ant world!

Many thanks, Matt


(Szczepan Faber) #2

Hey,

Say the jar task that produces the binary with generated sources is called ‘generatedSrcJar’. Then, you need something like this:

configurations {
  generated
}
  artifacts {
  generated generatedSrcJar
 }

‘uploadGenerated’ is the task that deals with upload (notice the naming convention ‘upload’ + configuration name, similar to ‘uploadArchives’ task). It needs to be configured so that it knows where & how to upload (it seems you have figure that out out already)

Hope that helps!


(Matt Painter) #3

Thanks so much - I hadn’t twigged that the ‘uploadArchives’ task was dynamically linked to the ‘archives’ configuration and that I’d get an ‘uploadGenerated’ for free. Brilliant!