Ivy-publish plugin not generating dependencies for non-compile configurations

I have a multi-project configuration that’s correctly publishing all modules to an ivy repository, including (in one module) a jar file that belongs to a non compile configuration. However, the generated ivy.xml only includes dependencies for the compile configuration. I expect to see dependencies listed for the extra configuration.I’m sure I’m missing something obvious, but can’t find anything about this in the current docs.

From main build.gradle

----
publishing {
  publications {
    ivyJava(IvyPublication) {
      from components.java
      configurations {
        testCompile {
          extend "compile"
        }
        integrationTestCompile {
          extend "testCompile"
        }
        testArtifacts {
          extend "integrationTestCompile"
        }
      }
    }
  }
  repositories {
    ivy {
      url "${System.properties['user.home']}/.ivy2/local"
      layout "pattern", {
        artifact "[organisation]/[revision]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"
        ivy      "[organisation]/[revision]/[module]/ivy.xml"
      }
    }
  }
}

----

From subproject build.gradle

----
configurations {
  testArtifacts.extendsFrom integrationTestCompile
}

task testJar(type: Jar) {
  classifier "test"
  from sourceSets.integrationTest.output
}

artifacts {
  testArtifacts testJar
}

publishing {
  publications {
    ivyJava(IvyPublication) {
      artifact(testJar) {
        type "jar"
        classifier "test"
        conf "testArtifacts"
      }
    }
  }
}

dependencies {
  compile "org.springframework.data:spring-data-rest-webmvc"
  compile "org.springframework.boot:spring-boot-starter-data-jpa"
  compile "org.springframework.security:spring-security-core"
  compile "com.graphql-java:graphql-spring-boot-starter:3.10.0"
  compile "com.graphql-java:graphql-java-tools:4.3.0"
  compile "org.flywaydb:flyway-core:${flywayVersion}"

  testCompile project(":hub-test-tools")

  testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
  testCompile "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}"
  testCompile "org.junit.platform:junit-platform-runner:${junitPlatformVersion}"

  integrationTestCompile project(":hub-test-tools")

  integrationTestCompile "org.springframework.boot:spring-boot-starter-test"
  integrationTestCompile "org.springframework.security:spring-security-test"
  integrationTestCompile "com.github.sbrannen:spring-test-junit5:${jitPackVersion}"
  integrationTestCompile "org.springframework.ws:spring-ws-test"
  integrationTestCompile "org.awaitility:awaitility:${awaitilityVersion}"
  integrationTestCompile "org.apiguardian:apiguardian-api:${apiGuardianVersion}"
}

----

Generated subproject ivy.xml (the only dependencies generated are for compile->default)

----
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
  <info organisation="e2x-ihub" module="hub-model" revision="1.0.0" status="integration" publication="20180529152136"/>
  <configurations>
    <conf name="compile" visibility="public"/>
    <conf name="default" visibility="public" extends="compile,runtime"/>
    <conf name="integrationTestCompile" visibility="public" extends="testCompile"/>
    <conf name="runtime" visibility="public"/>
    <conf name="testArtifacts" visibility="public" extends="integrationTestCompile"/>
    <conf name="testCompile" visibility="public" extends="compile"/>
  </configurations>
  <publications>
    <artifact name="hub-model" type="jar" ext="jar" conf="compile"/>
    <artifact name="hub-model" type="jar" ext="jar" conf="testArtifacts" m:classifier="test"/>
  </publications>
  <dependencies>
    <dependency org="org.apache.commons" name="commons-lang3" rev="3.5" conf="compile-&gt;default"/>
    <dependency org="org.springframework.data" name="spring-data-rest-webmvc" rev="" conf="compile-&gt;default"/>
    <dependency org="org.springframework.boot" name="spring-boot-starter-data-jpa" rev="" conf="compile-&gt;default"/>
    <dependency org="org.springframework.security" name="spring-security-core" rev="" conf="compile-&gt;default"/>
    <dependency org="com.graphql-java" name="graphql-spring-boot-starter" rev="3.10.0" conf="compile-&gt;default"/>
    <dependency org="com.graphql-java" name="graphql-java-tools" rev="4.3.0" conf="compile-&gt;default"/>
    <dependency org="org.flywaydb" name="flyway-core" rev="4.1.2" conf="compile-&gt;default"/>
  </dependencies>
</ivy-module>

----

The ivy-publish (and maven-publish) plugins only publish what’s part of the component definition. For a java component that’s currently it’s api and its runtime dependencies. There is currently no way to configure or extend this (except for the low-level withXml hook), though that is the eventual goal. What’s the intention behind publishing test dependencies?

Thanks for the super-fast response! We have a core component and a few dependent ones, which in turn are used by specific projects to build data integrations. The core module provides an additional test jar that (a) is used in its own testing and (b) makes it possible for downstream systems to write tests against the core.

I suspect the easiest way to think about this will be to promote the test code to a sub-project of its own, and publish that as a module with its own compile/runtime dependencies. Gradle dependencies will be able to pull that into a test configuration.

Yes, that’s the way to go for now. We do intend to support having test fixtures published from the same project as the main code, but that’s not there yet.

Made the changes, all appears to be well. Thanks again for your help

1 Like