We can publish a pre-built jar into a Maven repo using Gradle by using java plugin and maven-publish plugin. maven-publish has a feature to inject dependencies into generated pom using pom.withXml block.
Hereby I'm giving a sample build.gradle file which generates a pom.xml of the pre-built artifact with its specified dependencies. You can try this suggestion as shown below.
apply plugin: "maven-publish"
apply plugin: "java"
dependencies {
compile "dependency:antlr:2.7.7"
compile "dependency:commons-beanutils:1.9.3"
compile "dependency:dom4j:1.6.1"
compile "dependency:jettison:1.3.8"
}
publishing {
repositories {
maven {
url "$mavenUrl"
credentials {
username = "$mavenUser"
password = "$mavenPwd"
}
}
}
publications {
maven(MavenPublication) {
groupId "test"
artifactId "myArtifact"
version "1.0"
artifact ("/scratch/test/jars/myArtifact.jar")
pom.withXml {
def dependencies = asNode().appendNode("dependencies")
configurations.compile.allDependencies.each { dep ->
def depNode = dependencies.appendNode("dependency")
depNode.appendNode("groupId", dep.group)
depNode.appendNode("artifactId", dep.name)
depNode.appendNode("version", dep.version)
}
}
}
}
}
The generated pom will look like as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>dependency</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>dependency</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>dependency</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>dependency</groupId>
<artifactId>jettison</artifactId>
<version>1.3.8</version>
</dependency>
</dependencies>
</project>
I guess this might answer your question