What is considered best practice for new publishing model in multi-project builds where root project sets up the publication in a subprojects closure and each subproject needs to affect value(s) in the POM? Specific values I am thinking of here are name and description. Gradle POM generation already handles the different artifact names across the projects.
Should each subproject just do the following snippet individually?
Or is there a way to define POM name/description on the subprojects (as prooperties, etc) and have that available when the root project runs its subprojects{} closure?
Actually I found that you cannot have each subproject attempt to access that named publication. That leads to errors : “Publication with name ‘main’ added multiple times”
So each reference (once in the root project’s subprojects closure and then in the subproject build script) attempts to add the publication. So that option is not really an option…
You can access a project properties directly in the ‘publishing’ block, even if it’s defined in a ‘subprojects’ block. (The ‘publishing’ block is evaluated lazily on first access):
You can also further customise the publication directly in a project, like this:
project('projectA') {
publishing {
publications {
maven {
// Do subproject-specific stuff here
}
}
}
You’ll see that no type is given to the ‘maven’ publication, signifying it is an accessor.
Note that ‘publications’ is a PublicationContainer, which leverages the newly added PolymorphicDomainObjectContainer support. No doubt that more documentation and examples are required to clarify the usage of this new type of model element.