Having Gradle publish a standalone POM file to Artifactory

I’m trying to have Gradle upload a “Bills of Materials” POM file to Artifactory.

I already have a working project which deploys a POM file and a dummy jar file. However this doesn’t work because the “packaging” inside the POM file is set to “jar” (because I apply the “java” plugin).

I tried to force the packaging to “pom” by using the available callbacks but then the upload to Artifactory fails with an HTTP 409 (Conflict) error. I suppose this is caused because I upload a jar file but the packaging of the associated POM file is set to “pom” (instead of jar) so Artifactory complains.

I tried to stop generating the jar file but in this case nothing gets uploaded.

What’s the theory for having a Gradle build publish a unique POM file to Artifactory ? It seems that using the ‘maven’ plugin is not the way to go.

Any piece of advice would be greatly appreciated !

Thanks

1 Like

I know this is old, but I had the same problem, so maybe this helps somebody else, too.
Also if there’s a better way, I’d really like to now, because this seems archaic.

This is from http://grails.io/post/86513009278/publishing-a-pom-with-gradle but needed some adjustments.
This currently only publishes to mavenLocal(), but it should be possible to extend, see the docs at http://maven.apache.org/ant-tasks/examples/install-deploy.html

import org.gradle.api.internal.project.IsolatedAntBuilder

configurations {
	mavenAntTasks
}

repositories {
	mavenCentral()
}

dependencies {
	mavenAntTasks 'org.apache.maven:maven-ant-tasks:2.1.3'
}

task install {
	doLast {
		def antBuilder = services.get(IsolatedAntBuilder)
		antBuilder.withClasspath(configurations.mavenAntTasks).execute {
			taskdef(resource: 'org/apache/maven/artifact/ant/antlib.xml')

			pom(file: "${projectDir}/pom.xml", id: "pom")

			install(file: "${projectDir}/pom.xml") {
				pom refid: "pom"
			}
		}
	}
}

Running “./gradlew” against the build below will generate a unique POM file (that you can possibly customize by using the standard hooks).

apply plugin: 'base'
apply plugin: 'maven-publish'

defaultTasks 'clean', 'publish'

group='com.acme.project'
version='1.0.0'

publishing {
  publications {
    mavenJava(MavenPublication) {
    }
  }

  repositories {
    maven {
      url "${new File(buildDir, 'local-repo').toURL()}"
    }
  }
}

Yes, of course I know that.

However that does not really help:

I have an existing Bill-Of-Material pom.xml that is exactly 1555 lines long. It is carefully tuned to fix all (transitive) dependency versions, apply exclusion rules and provide properties to the build.
I really, really, do not want to convert that to gradle format.
Also for a while both maven and gradle builds will co-exist. Having a single BOM for both simplifies matters a lot.
Currently we are using the ‘io.spring.dependency-management’ plugin to read in the pom.

It sounds like a very, very simple task: Just take this pom.xml and publish it.