roomsg
roomsg

Reputation: 1857

Publish (rootproject) pom without (rootproject) publishing artifact / packaging = pom

I'm migrating one of our projects from maven to gradle: it's a gradle multi-project & all subprojects are publishing artifacts to artifactory. So far so good.

The legacy (maven-based) build environment however also expects the root project to publish a pom file with the "packaging" node equal to "pom" (common maven behaviour, so it seems)

So now, I'm trying to have this generated by Gradle, but only find ways to customize an automatically generated pom for each artifact, I can't find a way to generate/upload a pom without publishing an actual artifact.

Workaround for now is to have the root project use the java plugin, generate/install an empty jar and manipulate the generated pom to conform to maven expectations (packaging=pom), but that's a hack.

Is there a way to have this root pom file generated with gradle ?

Example project:

settings.gradle

rootProject.name = 'MultiProject'
include 'child01', 'child02'
rootProject.children.each { it.name = rootProject.name + "-" + it.name }

build.gradle

subprojects {
  apply plugin: 'java'
}
allprojects {
  apply plugin: 'maven'
  group = 'my_group'
  version = '0.0.1-SNAPSHOT'
}

EDIT (current workaround), addition to build.gradle

// workaround to generate pom
apply plugin: 'java'

configurations {
    pomCreation
}

task createPom {
    ext.newPomFile = "${buildDir}/blabla.pom"
    doLast {
        pom {
            project {
                packaging 'pom'
            }
        }.writeTo(newPomFile)
    }
}
install.dependsOn(createPom)

artifacts {
    pomCreation file(createPom.newPomFile)
}

Upvotes: 4

Views: 1792

Answers (1)

Fredericson
Fredericson

Reputation: 75

I would use the gradle maven-publish plugin for that. With that plugin you can define your specific pom and don't have to upload other artifacts. Here an example:

publishing {
    publications {
    maven(MavenPublication) {
        pom.withXml{
            def xml = asNode()
            xml.children().last() + {               
                delegate.dependencies {
                    delegate.dependency {
                        delegate.groupId 'org.springframework'
                        delegate.artifactId 'spring-context'
                        delegate.version( '3.2.8.RELEASE' )
                    }
                }
            }
        }
    }
}

Upvotes: 1

Related Questions