Asaf Marine
Asaf Marine

Reputation: 393

gradle publish does not include dependencies in pom

When I try to publish artifacts to a personal artifactory repository, when I look in the repository I notice that the pom that was published does not include the dependencies that the proeject has, can you please explain what is wrong with my build?

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        // Add this line
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
    }
}



// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'maven'
group 'CaptchaSolving'
version '1.0.0'



sourceCompatibility = 1.5

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    maven {
        url 'https://artifactory.lyoko.pw:443/libs-release-local'
        credentials {
            username = "${artifactory_username}"
            password = "${artifactory_password}"
        }
    }
}



sourceSets {
    main {
        java {
            srcDir 'src/'
        }
    }
}






// In this section you declare the dependencies for your production and test code
dependencies {
    compile(group: 'com.pragone.custom', name: 'jpHash', version: '1.0.1')
}



task assembleRelease(type: Jar, dependsOn:classes) {
    classifier = 'release'
    manifest {
        attributes 'Implementation-Title': project.group,
                'Implementation-Version': version,
                'Main-Class': ''
    }
    baseName = project.name
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar


}



artifacts {
    archives assembleRelease
}

def libraryGroupId = group
def libraryArtifactId = rootProject.name
def libraryVersion = version
publishing {
    publications {
        jar(MavenPublication) {
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId
            artifact("$buildDir/libs/${artifactId}-${libraryVersion}.jar")

        }
    }
}

artifactory {
    contextUrl = 'https://artifactory.lyoko.pw'
    publish {
        repository {
            repoKey = 'libs-release-local'

            username = artifactory_username
            password = artifactory_password
        }
        defaults {
            publications('jar')
            publishArtifacts = true

            properties = ['qa.level': 'basic', 'dev.team': 'core']
            publishPom = true
        }
    }
}

as you can see, there is only one dependency,

and the pom that gets published is:

<?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>CaptchaSolving</groupId>
  <artifactId>CaptchaSolving</artifactId>
  <version>1.0.0</version>
</project>

(obtained from the view tab at artifactory) as you can see it has none of the repositories that I specified.

so I just want the resulting pom to include the repositories and the dependencies this project depends on.

Upvotes: 6

Views: 9176

Answers (1)

Asaf Marine
Asaf Marine

Reputation: 393

I managed to solve the problem after seeing this post and trying a few things out.

It appears, the block:

publishing {
    publications {
        jar(MavenPublication) {
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId
            artifact("$buildDir/libs/${artifactId}-${libraryVersion}.jar")

        }
    }
}

was missing:

from components.java

so the final solution is:

publishing {
    publications {
        jar(MavenPublication) {
            from components.java
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId
            artifact("$buildDir/libs/${artifactId}-${libraryVersion}.jar")

        }
    }
}

Upvotes: 11

Related Questions