I have a gradle project containing multiple subprojects. The subprojects use the maven-publish plugin to publish one or multiple maven artifacts. I want to add license and company (and maybe other) information to the POMs of the artifacts.
I found how to do this, like this:
publishing {
publications {
mySubprojectsPublication(MavenPublication) {
artifact subprojectsPackageTask
pom {
licenses {
license {
name = '...'
url = '...'
distribution = 'repo'
comments = '...'
}
}
organization {
name = 'My Organization'
url = 'https://www.MyOrgUrl.com'
}
}
}
}
With multiple subprojects (and potentially mutliple publications per subproject), it seems to be suboptimal and hard to maintain to copy&paste the pom { ... }
section to each of the publications across multiple build.gradle
files.
QUESTION: Is there a way to specify this for all publications in the project? (All publications share the same license type)
I found a solution myself...
I add the following to the root
build.gradle
:If the root
build.gradle
doesn't already use the maven-publish plugin itself, you need to add it as well:The model {} block is required, so that the pom info is added to all configured publications of the project after they have been configured.