Ivy publish for sources and javadoc

hi there

I’m trying to publish a jar , well actually 3 jars - classes,sources and javadoc,by using plugin ‘ivy-publish’. But executing ‘gradle publish’ always ends in:

Could not parse Ivy file file:/C:/dev/ie8-git/services/restgenericclient/build/publications/ivyJava/ivy.xml

Problem occurred while parsing ivy file: Cannot add artifact ‘iengine-service-restgenericclient.jar(sources)’ to configuration ‘sources’ of module tie#iengine-service-restgenericclient;1.0.0 because this configuration doesn’t exist!

build.gradle looks as following →

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'ivy-publish'
  group = 'tie'
version = '1.0.0'
archivesBaseName = 'iengine-service-restgenericclient'
  compileJava {
  sourceCompatibility = 1.6
  targetCompatibility = 1.6
}
  jar {
  manifest {
    attributes 'Implementation-Title': 'REST Generic Client',
    'Implementation-Version': version
  }
}
  task sourcesJar(type: Jar, dependsOn: classes) {
  classifier = 'sources'
  from sourceSets.main.allSource
 }
  task javadocJar(type: Jar, dependsOn: javadoc) {
  classifier = 'javadoc'
  from javadoc.destinationDir
}
  artifacts {
  archives sourcesJar
  archives javadocJar
}
  repositories {
  mavenCentral()
}
  dependencies {
  compile 'org.apache.commons:commons-lang3:3.3.2'
  compile 'org.springframework:spring-web:4.0.6.RELEASE'
  compile 'org.apache.httpcomponents:httpclient:4.3.5'
        compile 'com.fasterxml.jackson.core:jackson-core:2.4.2'
  compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2'
  compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.2'
    testCompile 'junit:junit:4.11'
  testCompile 'org.hamcrest:hamcrest-all:1.3'
  testCompile 'org.mockito:mockito-all:1.9.5'
}
  publishing {
    publications {
   ivyJava(IvyPublication) {
      module archivesBaseName
      from components.java
      artifact(sourcesJar) {
        type "sources"
        conf "sources"
      }
      artifact(javadocJar) {
        type "javadoc"
        conf "javadoc"
      }
        }
  }
}

generated xml

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
  <info organisation="tie" module="iengine-service-restgenericclient" revision="1.0.0" status="integration" publication="20140903223020"/>
  <configurations>
    <conf name="default" visibility="public" extends="runtime"/>
    <conf name="runtime" visibility="public"/>
  </configurations>
  <publications>
    <artifact name="iengine-service-restgenericclient" type="jar" ext="jar" conf="runtime"/>
    <artifact name="iengine-service-restgenericclient" type="sources" ext="jar" conf="sources" m:classifier="sources"/>
    <artifact name="iengine-service-restgenericclient" type="javadoc" ext="jar" conf="javadoc" m:classifier="javadoc"/>
  </publications>
  <dependencies>
    <dependency org="org.apache.commons" name="commons-lang3" rev="3.3.2" conf="runtime->default"/>
    <dependency org="org.springframework" name="spring-web" rev="4.0.6.RELEASE" conf="runtime->default"/>
    <dependency org="org.apache.httpcomponents" name="httpclient" rev="4.3.5" conf="runtime->default"/>
    <dependency org="com.fasterxml.jackson.core" name="jackson-core" rev="2.4.2" conf="runtime->default"/>
    <dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.4.2" conf="runtime->default"/>
    <dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.4.2" conf="runtime->default"/>
  </dependencies>
</ivy-module>

Does anybody know how to publish sources & javadoc artefact to my ivy repository?

thanks for help. cyrill

The error is because you are specifying configurations for the artifacts (“sources” and “javadoc”) that don’t exist. You should use one of the existing configurations unless you have a reason to use a separate configuration. The “runtime” configuration is probably what you want.

Thanks for your answer. I’d like to seperate “runtime” from “sources” configuration. For example in ivy.xml of aopalliance in my local gradle cache (C:\Users\tiezad.gradle\caches\modules-

2\metadata-2.12\descriptors\aopalliance\aopalliance\1.0\8eb80c2e7e631bf662f14a25bb19e6c0) those two configurations are seperated as well.

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
  <info organisation="aopalliance" module="aopalliance" revision="1.0" status="release" publication="20070226234340">
    <license name="Public Domain"/>
    <description homepage="http://aopalliance.sourceforge.net">AOP Alliance</description>
  </info>
  <configurations>
    <conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
    <conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
    <conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
    <conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation
   classpath, and is not transitive."/>
    <conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths,
   but not the compile classpath." extends="compile"/>
    <conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation
   and execution phases." extends="runtime"/>
    <conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and
   is not looked up in a repository."/>
    <conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
    <conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
    <conf name="optional" visibility="public" description="contains all optional dependencies"/>
  </configurations>
  <publications>
    <artifact name="aopalliance" type="jar" ext="jar" conf="master"/>
    <artifact name="aopalliance" type="source" ext="jar" conf="sources" m:classifier="sources"/>
  </publications>
</ivy-module>

Is it possible to add this configuration “sources”?

You should just be able to define those configurations then:

configurations {
  sources
  javadoc
}

Still same error.

FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':publishIvyJavaPublicationToIvyRepository'.
> Failed to publish publication 'ivyJava' to repository 'ivy'
   > Could not parse Ivy file file:/C:/dev/ie8-git/services/restgenericclient/build/publications/ivyJava/ivy.xml
      > Problem occurred while parsing ivy file: Cannot add artifact 'iengine-service-restgenericclient.jar(source)' to configuration 'sources' of module tie#iengine-service-restgenericclient;1.0.0 because this configuration doesn't exist!

I’ve found a workaround.

descriptor.withXml {
                                asNode().configurations[0].appendNode('conf', [name: 'sources', visibility: 'public'])
                                asNode().configurations[0].appendNode('conf', [name: 'javadoc', visibility: 'public']) }

This way I can add those two configurations manually to ivy.xml.

Could it be that ivy-plugin doesn’t support other configurations than default & runtime?

Looks like a defect. You can work around it as such:

publications {
        ivyJava(IvyPublication) {
            from components.java
            configurations.create('sources')
              artifact(sourceJar) {
                conf "sources"
                classifier "sources"
            }
        }
    }

It worked… thx for helping out.