Page 1 of 1

It is worth mentioning that the Java plugin

Posted: Thu Feb 20, 2025 8:49 am
by sujonkumar6300
Adds the concept of sourceSets to Gradle, which are precisely the sets of source code files. By default two sets are defined: main, with the project classes, and test, with the unit tests. By default, the sources of the main set are in src/main/java. Since we are following conventions, it is not necessary to specify all this explicitly in our script. In the sourcesJar task, we are including ALL the sources (including resources) of the main set.

And to each Jar we put a classifier, which will be in the name of the resulting file, since by default Gradle will create the Jars using the project name, the version and the classifier.

And now we can run these tasks sequentially, just specify each one on the Peru Mobile Database command line. So we type gradle javadocJar sourcesJar and at the end in the build/libs directory we will have HolaSG-0.1-javadoc.jar and HolaSG-0.1-sources.jar.

But these are tasks specifically defined in this project, they don't seem to be standard stuff; the idea of ​​these scripts and tools is to make life easier for anyone who wants to build the project, allowing them to run the script without even having to look at it; honestly, how many of us have seen a Makefile of a project we downloaded and built from source? We just run ./configure && make && sudo make install and that's it. Fortunately, the Java plugin for Gradle detects any Jar tasks and automatically adds them to the assemble task. And that task in turn depends on the build tasks (but not the test tasks). So we can define some tasks to be executed by default in our script. Let's add this line after where we define the version: