# Publishing Java Libraries Sample

version 9.3.0-20251220022016+0000

- Groovy DSL

- Kotlin DSL

| You can open this sample in an IDE that supports Gradle.

This sample shows how to publish a Java library to a repository. The library has no dependencies and the build has minimal configuration.

my-library/build.gradle.kts

    plugins {
        `java-library`
        `maven-publish`
    }

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

    publishing {
        publications {
            create<MavenPublication>("library") {
                from(components["java"])
            }
        }
        repositories {
            maven {
                url = uri(layout.buildDirectory.dir("publishing-repository"))
            }
        }
    }

my-library/build.gradle

    plugins {
        id 'java-library'
        id 'maven-publish'
    }

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

    publishing {
        publications {
            library(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                url = layout.buildDirectory.dir("publishing-repository")
            }
        }
    }

To publish the library:

    $ ./gradlew publish

    BUILD SUCCESSFUL
    5 actionable tasks: 5 executed
    $ tree build/publishing-repository
    build/publishing-repository
    └── org
        └── gradle
            └── sample
                └── my-library
                    ├── 1.0.2
                    │   ├── my-library-1.0.2.jar
                    │   ├── my-library-1.0.2.jar.md5
                    │   ├── my-library-1.0.2.jar.sha1
                    │   ├── my-library-1.0.2.jar.sha256
                    │   ├── my-library-1.0.2.jar.sha512
                    │   ├── my-library-1.0.2.module
                    │   ├── my-library-1.0.2.module.md5
                    │   ├── my-library-1.0.2.module.sha1
                    │   ├── my-library-1.0.2.module.sha256
                    │   ├── my-library-1.0.2.module.sha512
                    │   ├── my-library-1.0.2.pom
                    │   ├── my-library-1.0.2.pom.md5
                    │   ├── my-library-1.0.2.pom.sha1
                    │   ├── my-library-1.0.2.pom.sha256
                    │   └── my-library-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 Publishing Libraries.