# Groovy Library Publishing Sample

version 6.5-milestone-1

- Groovy DSL

- Kotlin DSL

| You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how a Groovy library can be published to a repository with Gradle.

build.gradle

    plugins {
        id 'groovy'
        id 'maven-publish'
    }

    version = '1.0.2'
    group = 'org.gradle.sample'

    repositories {
        jcenter()
    }

    dependencies {
        implementation 'org.codehaus.groovy:groovy-all:2.5.7'
    }

    publishing {
        publications {
            library(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                url = uri("${buildDir}/publishing-repository")
            }
        }
    }

build.gradle.kts

    plugins {
        groovy
        `maven-publish`
    }

    version = "1.0.2"
    group = "org.gradle.sample"

    repositories {
        jcenter()
    }

    dependencies {
        implementation("org.codehaus.groovy:groovy-all:2.5.7")
    }

    publishing {
        publications {
            create<MavenPublication>("library") {
                from(components.getByName("java"))
            }
        }
        repositories {
            maven {
                url = uri("${buildDir}/publishing-repository")
            }
        }
    }

To publish the library:

    $ ./gradlew publish

    BUILD SUCCESSFUL
    4 actionable tasks: 4 executed
    $ tree build/publishing-repository
    build/publishing-repository/
    └── org
        └── gradle
            └── sample
                └── library-publishing
                    ├── 1.0.2
                    │   ├── library-publishing-1.0.2.jar
                    │   ├── library-publishing-1.0.2.jar.md5
                    │   ├── library-publishing-1.0.2.jar.sha1
                    │   ├── library-publishing-1.0.2.jar.sha256
                    │   ├── library-publishing-1.0.2.jar.sha512
                    │   ├── library-publishing-1.0.2.module
                    │   ├── library-publishing-1.0.2.module.md5
                    │   ├── library-publishing-1.0.2.module.sha1
                    │   ├── library-publishing-1.0.2.module.sha256
                    │   ├── library-publishing-1.0.2.module.sha512
                    │   ├── library-publishing-1.0.2.pom
                    │   ├── library-publishing-1.0.2.pom.md5
                    │   ├── library-publishing-1.0.2.pom.sha1
                    │   ├── library-publishing-1.0.2.pom.sha256
                    │   └── library-publishing-1.0.2.pom.sha512
                    ├── maven-metadata.xml
                    ├── maven-metadata.xml.md5
                    ├── maven-metadata.xml.sha1
                    ├── maven-metadata.xml.sha256
                    └── maven-metadata.xml.sha512

    5 directories, 20 files

For more information, see Groovy Plugin reference chapter.