# New publishing model best practices for multi-project builds and generated POM

**URL:** <https://discuss.gradle.org/t/new-publishing-model-best-practices-for-multi-project-builds-and-generated-pom/4680>\
**Category:** Old Forum Archive\
**Created:** [April 5, 2013, 11:54am UTC](https://discuss.gradle.org/t/new-publishing-model-best-practices-for-multi-project-builds-and-generated-pom/4680 "2013-04-05T11:54:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [April 5, 2013, 11:54am UTC](https://discuss.gradle.org/t/new-publishing-model-best-practices-for-multi-project-builds-and-generated-pom/4680/1 "2013-04-05T11:54:00Z")

</div>

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?

```gradle
publications {
    mavenCustom(MavenPublication) {
        pom.withXml {
            asNode()
                    .appendNode( 'name', "This (sub)project's specific name" )
                    .appendNode( 'description', "This (sub)project's specific description" )
        }
    }
}

```

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?

Other options?

---

<div class="post-metadata">

**Author:** ![Steve\_Ebersole](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/steve_ebersole/32/9763_2.png) [@Steve\_Ebersole](https://discuss.gradle.org/u/Steve_Ebersole)\
**Post date:** [April 5, 2013, 10:43pm UTC](https://discuss.gradle.org/t/new-publishing-model-best-practices-for-multi-project-builds-and-generated-pom/4680/2 "2013-04-05T22:43:00Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [April 6, 2013, 7:39pm UTC](https://discuss.gradle.org/t/new-publishing-model-best-practices-for-multi-project-builds-and-generated-pom/4680/3 "2013-04-06T19:39:00Z")

</div>

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):

```gradle
subprojects {
  apply plugin: 'maven-publish'
    version = '1.0'
  group = 'myorg'
    publishing {
    publications {
      maven(MavenPublication) {
        pom.withXml {
          asNode().appendNode("name", project.name)
          asNode().appendNode("custom", project.custom)
          asNode().appendNode("description", project.description)
        }
      }
    }
  }
}
  project('projectA') {
  description = "Project A"
  ext.custom = "custom value"
}

```

You can also further customise the publication directly in a project, like this:

```gradle
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](http://www.gradle.org/docs/nightly/javadoc/org/gradle/api/publish/PublicationContainer.html), which leverages the newly added [PolymorphicDomainObjectContainer](http://www.gradle.org/docs/nightly/javadoc/org/gradle/api/PolymorphicDomainObjectContainer.html) support. No doubt that more documentation and examples are required to clarify the usage of this new type of model element.
