Missing POM dependencies in a multi-sourceSet project using maven-publish

Hi all!

I have an additional sourceSet in my project with an extra dependency. When I try to publish and artifact for this sourceSet with maven-publish, the POM doesn’t have any dependencies.

Here’s my build.gradle:

apply plugin: 'java'
apply plugin: 'maven-publish'

repositories {
    jcenter()
    mavenLocal()
}

sourceSets {
    contract {
        java {
            srcDirs = ['src/contractTests/java']
        }
    }
}

configurations {
    contractCompile.extendsFrom testCompile
}

dependencies {
    compile 'contractdemo:utils:+'

    testCompile 'junit:junit:4.12'
    contractCompile 'org.hamcrest:java-hamcrest:2.0.0.0'
}

task testJar(type: Jar) {
    from sourceSets.contract.output
}

publishing {
    publications {
        test(MavenPublication) {
            groupId 'contractdemo'
            artifactId 'processing-utils-contract'
            version '1.0'

            artifact testJar
        }
    }
}

And here’s the resulting POM:

<?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>contractdemo</groupId>
  <artifactId>processing-utils-contract</artifactId>
  <version>1.0</version>
</project>

I’d expect to see the hamcrest dependency in there, but it’s not. This issue is very similar to this old one.

Would anyone have an idea how to resolve this?