'ivy-publish': how to add project dependencies to the ivy module descriptor for none java|web projects


(vladimir.ovod) #1

I’m trying to use a new publishing mechanism (‘ivy-publish’ plugin) for uploading files to an ivy repository. In a publication I don’t use ‘from components.java’ or ‘from components.web’ since my project is neither web nor java. Files are added to the publication via the artifact() mechanism, eg: apply plugin: ‘base’ apply plugin: ‘ivy-publish’

version = ‘0.0.1’ group = ‘anygroup’

task wrapper(type: Wrapper) {

gradleVersion = ‘1.6’ }

repositories {

mavenCentral() }

configurations {

myConfiguration }

// Declare some dependency for testing purposes dependencies {

myConfiguration group: ‘org.hibernate’, name: ‘hibernate’, version: ‘3.0.5’, transitive: true }

task generateFileTask << {

def f = new File(‘build/myGeneratedFile.ext’)

f << “something” }

publishing {

repositories {

ivy {

url ‘…/ivy.repo’

}

}

publications {

myPublication(IvyPublication) {

configurations {

myConfiguration { }

}

artifact(‘build/myGeneratedFile.ext’) {

name ‘myGeneratedFile’

conf ‘myConfiguration’

builtBy generateFileTask

}

}

} }

This works fine except that dependencies are not added to the ivy descriptor, see below:

<?xml version="1.0" encoding="UTF-8"?>

What would be a proper way to add project dependencies to a descriptor?

Thank you.


(vladimir.ovod) #2

Hmm, how to add a content of an ivy.xml to the post?


(vladimir.ovod) #3

Hmm, is it possible to edit my original post?


(Peter Niederwieser) #4

Usually it works until a reply has been posted. (Removing the reply may not help.)


#5

Currently, there’s no DSL for additing/editing dependencies in your publication. You have 3 options:

  1. Use the ‘withXml’ hook to add dependencies to the generated ivy.xml file 2. Create your own SoftwareComponent that will generate the correct publication. (Completely internal and unsupported at the moment). 3. Contribute to Gradle by helping out with the implementation of this story.

The first option is probably the simplest. Naturally, the third option would be my preference :). I’m happy to help out if you choose to contribute.


(vladimir.ovod) #6

Thank you, Peter.


(vladimir.ovod) #7

Thank you, Daz.

I’m afraid I’ll have will go for the option (1) :slight_smile:

Here is an example of what worked for me: publishing {

repositories {

ivy {

url ‘…/ivy.repo’

}

}

publications {

myPublication(IvyPublication) {

// Adding configurations to this publication.

configurations {

myConfiguration { }

// Seems that ‘default’ configuration is required here. Otherwise build fails with the exception :

// … Cannot add dependency ‘org.hibernate#hibernate;3.0.5’ to configuration ‘default’ of module …

‘default’ {

extend ‘myConfiguration’

}

}

descriptor {

withXml {

project.configurations.myConfiguration.resolvedConfiguration.firstLevelModuleDependencies.each { ResolvedDependency dep ->

def Map<String, String> dependencyDetails = new HashMap<>()

dependencyDetails.put(‘org’, dep.getModuleGroup())

dependencyDetails.put(‘name’, dep.getModuleName())

dependencyDetails.put(‘rev’, dep.getModuleVersion())

dependencyDetails.put(‘conf’, dep.getConfiguration())

asNode().dependencies[0].appendNode(‘dependency’, dependencyDetails)

}

}

}

artifact(‘build/myGeneratedFile.ext’) {

name ‘myGeneratedFile’

conf ‘myConfiguration,default’ // Not sure if I need to add ‘default’ here

builtBy generateFileTask

}

}

} }


(richard murray) #8

Is it possible to use a wildcard when specifying the artifact name? I’m doing something very similar - publishing an non Java/Web artifact to Ivy however the task generating my artifacts (a JavaExec task) produces different file names each time it runs.

I need something like this:

artifact('build/JWrapper-Windows32JRE-*-archive.p2.l2') {
  ..
}

This fails with the error ‘Could not normalize path for file ‘D:\tmp\jwrapper-ivy-publish-test\build\JWrapper-Windows32JRE-*-archive.p2.l2’.’

I’ve also tried this:

File compressedJre = fileTree('build').include('**/JWrapper-Windows32JRE-*-archive.p2.l2').singleFile
artifact(file(compressedJre )) {
    name compressedJre .name
    builtBy generateClientInstaller
}

But this fails as the file path is being evaluated at configuration time (I think) so the build directory is empty when this runs. I get the error ‘Expected directory ‘build’ to contain exactly one file, however, it contains no files.’

Thanks, Richard.


#9

Please raise a new forum issue for this question.