ScrappyDev
ScrappyDev

Reputation: 2778

How to auto-generate a pom file during build for upload to a maven2 repository?

I'm looking for gradle to create a clean pom with just the bare essentials like dependencies so I can upload it along the the jar, sources.jar, and javadoc.jar.

I also don't want to have to manually create the pom.

Upvotes: 0

Views: 578

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14510

Have a look at publishing, in particular with the maven-publish plugin, which handles this for you indeed.

But in order to have the minimal publication, this is a simple as:

plugins {
    `java`
    `maven-publish`
}

group = "org.example"
version = "1.0"

// dependencies declaration omitted

publishing {
    publications {
        create<MavenPublication>("myLibrary") {
            from(components["java"])
        }
    }

    repositories {
        maven {
            name = "myRepo"
            url = uri("file://${buildDir}/repo")
        }
    }
}

Note: This uses the Kotlin DSL, the Groovy version has a couple differences, see documentation

And then running ./gradlew publish will publish org.example:<project-name>:1.0

Upvotes: 1

Related Questions