# Gradle publication block - Demystify the DSL

**URL:** <https://discuss.gradle.org/t/gradle-publication-block-demystify-the-dsl/27104>\
**Category:** Help/Discuss\
**Created:** [May 25, 2018, 4:05pm UTC](https://discuss.gradle.org/t/gradle-publication-block-demystify-the-dsl/27104 "2018-05-25T16:05:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijayvepa](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vijayvepa](https://discuss.gradle.org/u/vijayvepa)\
**Post date:** [May 25, 2018, 4:05pm UTC](https://discuss.gradle.org/t/gradle-publication-block-demystify-the-dsl/27104/1 "2018-05-25T16:05:12Z")

</div>

I am trying to understand how a Gradle pro would read this block.

```gradle
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar {
                classifier "sources"
            }
        }
    }
}

```

What is the call stack if we convert this to java or groovy code?  
Based on intellisense from IntelliJ idea, I tried this one:

```groovy
publishing{
    publications{ pubContainer ->

        pubContainer.create('mavenJava').asType(MavenPublication.class){

        }

    }
}

```

Getting this error:

```gradle
Cannot create a Publication named 'mavenJava' because this container
 does not support creating elements by name alone.
 Please specify which subtype of Publication to create. Known subtypes are: MavenPublication

```

---

<div class="post-metadata">

**Author:** ![vijayvepa](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vijayvepa](https://discuss.gradle.org/u/vijayvepa)\
**Post date:** [May 25, 2018, 4:36pm UTC](https://discuss.gradle.org/t/gradle-publication-block-demystify-the-dsl/27104/2 "2018-05-25T16:36:05Z")

</div>

Got it working as below. This code can be introspected better in IntelliJ:

```gradle
publishing{
    publications{ pubContainer ->

        pubContainer.create('mavenJava', MavenPublication.class){ mavenPublication ->

            mavenPublication.from(components.getByName('java'))
            mavenPublication.artifact(sourceJar, { a->
                a.classifier('sources')
            })
        }

    }
}

```
