I have a gradle script which uploads multiple jars to maven repo (Artifactory)
but the pom files generated with it are standard one and doesn't contain any dependency information
I am able to modify the script to upload a single jar with custom pom file by following below article
Gradle not including dependencies in published pom.xml
(UploadWithPom.gradle attached)
apply plugin: 'maven-publish'
apply plugin: 'java'
dependencies {
compile "com.fasterxml.jackson.core:jackson-annotations:2.13.3"
compile "com.fasterxml.jackson.core:jackson-databind:2.13.3"
}
publishing {
repositories {
maven {
url "<Artifactory url>"
credentials {
username = '<username>'
password = '<pwd>'
}
}
}
publications {
jar1(MavenPublication) {
groupId 'my.group.id'
artifactId 'localJar1'
version '1.0.0'
artifact ("localJar1.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)
depNode.appendNode("scope","compile")
}
}
}
}
}
Iam able to upload multiple jars separately (MultipleJarUpload.gradle) but it generated standard pom file content as below
apply plugin: 'maven-publish'
apply plugin: 'java'
publishing {
repositories {
maven {
url "<Artifactory url>"
credentials {
username = '<username>'
password = '<pwd>'
}
}
}
publications {
jar1(MavenPublication) {
groupId 'my.group.id'
artifactId 'localJar1'
version '1.0.0'
artifact ("localJar1.jar")
}
jar2(MavenPublication) {
groupId 'my.group.id'
artifactId 'localJar12'
version '1.0.0'
artifact ("localJar2.jar")
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>localJar1</artifactId>
<version>1.0.0</version>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>localJar2</artifactId>
<version>1.0.0</version>
</project>
I need to have the required pom files generated for all the jars with same build.gradle script
EDIT - 1 this gradle script is not part of any project, I am using it to upload few jars to Artifactory from linux terminal or from jenkins. My requirement is to upload jar1 with dependency A and B, and to upload jar2 with dependency C and D from same build.gradle script.
// set java home and path
// set gradle home and path
gradle -b build.gradle publish
I have added all the dependencies in dependencies section as shown below
dependencies {
// these are required for jar1
compile "org.apache.kafka:kafka-clients:3.3.1-test3"
compile "org.slf4j:slf4j-api:1.7.36"
// there are required for jar 2
compile "com.fasterxml.jackson.core:jackson-annotations:2.13.3"
compile "com.fasterxml.jackson.core:jackson-databind:2.13.3"
}
when I run the script, it uploads both the jars with all the dependencies in the pom file generated, is there a way to specify / filter dependencies for different jars.