3

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.

Flow
  • 23,572
  • 15
  • 99
  • 156
Martin L.
  • 680
  • 7
  • 14
  • [Spring](https://github.com/SpringSource/spring-framework) does it by naming every subproject spring-xxx. [hibernate](https://github.com/hibernate/hibernate-orm) does it this way as well. – JB Nizet Feb 03 '13 at 16:17
  • @JBNizet: Thanks, maybe this is not bad practice as i assumed in the first place. It could actually solve all problems. – Martin L. Feb 03 '13 at 17:30

3 Answers3

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

Alternatively, you could set archivesBaseName in a similar way.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
1

We're handling this by renaming the subprojects, new names will be taken into account when creating/naming your jars: ref: how to rename the project in gradle instead of using folder name?

include 'xxx', 'yyy'
rootProject.children.each { it.name = rootProject.name + it.name }
Community
  • 1
  • 1
roomsg
  • 1,811
  • 16
  • 22
0

For Kotlin: in the root project's build file:

subprojects {
    tasks.withType<Jar> {
        archiveBaseName.set("${rootProject.name}-${project.name}")
    }
}
jck
  • 170
  • 1
  • 7