Assembling archives
If we want to package the output of the new api
source set in our JAR file, we must define a new task ourselves. Gradle doesn't provide some magic to do this for us automatically; luckily, the task itself is very simple:
apply plugin: 'java' archivesBaseName = 'gradle-sample' version = '1.0' sourceSets { api } task apiJar(type: Jar) { appendix = 'api' from sourceSets.api.output } ...
The task apiJar
is a Jar
task. We define the appendix
property that is used to generate the final filename of the JAR file. We use the from()
method to point to the output directory of our api
source set, so all generated output is included in the JAR file. When we run the task apiJar
, a new JAR file gradle-sample-api-1.0.jar
is generated in the build/libs
directory:
$ gradle apiJar :compileApiJava UP-TO-DATE :processApiResources UP-TO-DATE :apiClasses UP-TO-DATE :apiJar BUILD SUCCESSFUL Total time: 2.998 secs
The base name of the JAR file is the project name, which is similar...