title: How to create a Gradle build file that publishes a Java project to Ivy repo with sources, correctly?
body: <p>First of all: I've found so much information about this, both on SO, Google, Gradle documentation etc., it makes my head spin, but no one single source has told me the <strong>correct</strong> way of publishing a plain old java project, with sources, to an Ivy repository, with correct configurations, maven classifiers, Ivy types, etc. Here's as far as I have gotten:</p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'ivy-publish'
  
  group 'com.example'
  version '0.1.0'
  
  repositories {
      ivy {
          name 'local'
          url "${System.properties['user.home']}/localivy"
      }
  }
  
  task sourceJar(type: Jar) {
      from sourceSets.main.java
      // If the classifier isn't put here, the source jar overwrites the compiled jar
      classifier "sources"
  }
  
  publishing {
      publications {
          ivy(IvyPublication) {
              configurations {
                  sources {}
              }
              from components.java
              descriptor.status = 'release'
              artifact(sourceJar) {
                  type "source"
                  conf "sources"
              }
          }
      }
      repositories {
          add project.repositories.local
      }
  }
  </code></pre>
  
  <p>This gives me the following error:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':publishIvyPublicationToLocalRepository'.
  &gt; Failed to publish publication 'ivy' to repository 'local'
     &gt; Could not parse Ivy file file:/Users/markus/code/publish-test/build/publications/ivy/ivy.xml
        &gt; Problem occurred while parsing ivy file: Cannot add artifact 'publish-test.jar(source)' to configuration 'sources' of module com.example#publish-test;0.1.0 because this configuration doesn't exist!
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  
  </code></pre>
  
  <p>Specifically, I am trying to not have the source in the runtime configuration (because clients that get the library then get the sources even though they only want the compile dependencies).</p>
  
  <p>Also, I am a bit confused that publishing sources (and javadocs for that matter) isn't a standard part of the <em>java</em> Gradle plugin, like publishing the compiled jar is.</p>
  
  <p>Any help from someone out there? Thanks!</p>
  
  <p>PS: My reference ivy.xml file is from Google Guava 15.0:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven"&gt;
      &lt;info organisation="com.google.guava"
          module="guava"
          revision="15.0"
          status="release"
          publication="20130906215249"
      &gt;
          &lt;description homepage=""&gt;
          Guava is a suite of core and expanded libraries that include
      utility classes, google&amp;apos;s collections, io classes, and much
      much more.
  
      Guava has two code dependencies - javax.annotation
      per the JSR-305 spec and javax.inject per the JSR-330 spec.
          &lt;/description&gt;
          &lt;m:dependency.management__org.easymock__easymock__scope&gt;test&lt;/m:dependency.management__org.easymock__easymock__scope&gt;
          &lt;m:dependency.management__com.google.caliper__caliper__scope&gt;test&lt;/m:dependency.management__com.google.caliper__caliper__scope&gt;
          &lt;m:dependency.management__junit__junit__scope&gt;test&lt;/m:dependency.management__junit__junit__scope&gt;
          &lt;m:dependency.management__org.truth0__truth__scope&gt;test&lt;/m:dependency.management__org.truth0__truth__scope&gt;
          &lt;m:properties__test.include&gt;**/*Test.java&lt;/m:properties__test.include&gt;
          &lt;m:properties__gpg.skip&gt;true&lt;/m:properties__gpg.skip&gt;
          &lt;m:dependency.management__org.mockito__mockito-core__scope&gt;test&lt;/m:dependency.management__org.mockito__mockito-core__scope&gt;
          &lt;m:properties__truth.version&gt;0.13&lt;/m:properties__truth.version&gt;
          &lt;m:properties__project.build.sourceEncoding&gt;UTF-8&lt;/m:properties__project.build.sourceEncoding&gt;
          &lt;m:dependency.management__javax.inject__javax.inject__version&gt;1&lt;/m:dependency.management__javax.inject__javax.inject__version&gt;
          &lt;m:dependency.management__org.truth0__truth__exclusion_0&gt;com.google.guava__guava&lt;/m:dependency.management__org.truth0__truth__exclusion_0&gt;
          &lt;m:dependency.management__junit__junit__version&gt;4.8.2&lt;/m:dependency.management__junit__junit__version&gt;
          &lt;m:dependency.management__com.google.caliper__caliper__version&gt;0.5-rc1&lt;/m:dependency.management__com.google.caliper__caliper__version&gt;
          &lt;m:dependency.management__com.google.caliper__caliper__exclusion_0&gt;com.google.guava__guava&lt;/m:dependency.management__com.google.caliper__caliper__exclusion_0&gt;
          &lt;m:dependency.management__org.truth0__truth__version&gt;0.13&lt;/m:dependency.management__org.truth0__truth__version&gt;
          &lt;m:dependency.management__com.google.code.findbugs__jsr305__version&gt;1.3.9&lt;/m:dependency.management__com.google.code.findbugs__jsr305__version&gt;
          &lt;m:properties__sonatypeOssDistMgmtSnapshotsUrl&gt;https://oss.sonatype.org/content/repositories/snapshots/&lt;/m:properties__sonatypeOssDistMgmtSnapshotsUrl&gt;
          &lt;m:dependency.management__org.easymock__easymock__version&gt;3.0&lt;/m:dependency.management__org.easymock__easymock__version&gt;
          &lt;m:dependency.management__org.mockito__mockito-core__version&gt;1.8.5&lt;/m:dependency.management__org.mockito__mockito-core__version&gt;
          &lt;m:maven.plugins&gt;org.apache.maven.plugins__maven-enforcer-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__1.0|null__maven-gpg-plugin__1.4|org.apache.maven.plugins__maven-enforcer-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__1.0|null__maven-gpg-plugin__1.4|org.apache.felix__maven-bundle-plugin__2.3.7|null__maven-compiler-plugin__null|null__maven-source-plugin__null|null__maven-dependency-plugin__null|org.codehaus.mojo__animal-sniffer-maven-plugin__null|org.apache.maven.plugins__maven-javadoc-plugin__null&lt;/m:maven.plugins&gt;
      &lt;/info&gt;
      &lt;configurations&gt;
          &lt;conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/&gt;
          &lt;conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/&gt;
          &lt;conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/&gt;
          &lt;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."/&gt;
          &lt;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"/&gt;
          &lt;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"/&gt;
          &lt;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."/&gt;
          &lt;conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/&gt;
          &lt;conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/&gt;
          &lt;conf name="optional" visibility="public" description="contains all optional dependencies"/&gt;
      &lt;/configurations&gt;
      &lt;publications&gt;
          &lt;artifact name="guava" type="bundle" ext="jar" conf="master"/&gt;
          &lt;artifact name="guava" type="source" ext="jar" conf="sources" m:classifier="sources"/&gt;
          &lt;artifact name="guava" type="javadoc" ext="jar" conf="javadoc" m:classifier="javadoc"/&gt;
      &lt;/publications&gt;
      &lt;dependencies&gt;
          &lt;dependency org="com.google.code.findbugs" name="jsr305" rev="1.3.9" force="true" conf="optional-&gt;compile(*),master(*)"/&gt;
          &lt;dependency org="javax.inject" name="javax.inject" rev="1" force="true" conf="optional-&gt;compile(*),master(*)"/&gt;
          &lt;override org="org.easymock" module="easymock" matcher="exact" rev="3.0"/&gt;
          &lt;override org="org.truth0" module="truth" matcher="exact" rev="0.13"/&gt;
          &lt;override org="com.google.caliper" module="caliper" matcher="exact" rev="0.5-rc1"/&gt;
          &lt;override org="org.mockito" module="mockito-core" matcher="exact" rev="1.8.5"/&gt;
          &lt;override org="javax.inject" module="javax.inject" matcher="exact" rev="1"/&gt;
          &lt;override org="junit" module="junit" matcher="exact" rev="4.8.2"/&gt;
          &lt;override org="com.google.code.findbugs" module="jsr305" matcher="exact" rev="1.3.9"/&gt;
      &lt;/dependencies&gt;
  &lt;/ivy-module&gt;
  </code></pre>