Search code examples
gradlemulti-project

Gradle multi-project naming: How can I set a property (e.g. baseName) for all subprojects?


I started using Gradle for multi-projects. However, the Gradle manual does not give many hints for the best practice regarding the naming of subprojects.

I have the multiproject with the name 'datalogger' that consists of two subprojects 'core' and 'entries':

- datalogger
--- core
--- entries

When I build the project, I get the jars 'core-1.0.jar' and 'entries-1.0.jar'. How do I manage that the naming is 'datalogger-core-1.0.jar' and 'datalogger-entries-1.0.jar' in a generic way? I know, I could change the name of the folders as follows:

- datalogger
--- datalogger-core
--- datalogger-entries

But that would not be regarded as good approach, I assume. I could also manually change the archivesBaseName of each project. But I would rather find a way to do this in a generic way, as mentioned before.


Solution

  • subprojects {
        tasks.withType(Jar) {
            baseName = "datalogger-$project.name"
        }
    }
    

    Alternatively, you could set archivesBaseName in a similar way.