How to reference a test jar from a project in a multi-project build

I have a multi-project build and projectB needs to reference the test jar produced projectA.

I have the following in projectA’s build script to publish the test jar.

task jarTests(type: Jar, dependsOn: testClasses) {
    classifier = 'tests'
    from sourceSets.test.output
}
  artifacts {
    archives jarTests
}

What do I need to put in projectB’s build script in order to add projectA’s test jar to its testCompile configuration?

testCompile project(path: ‘:projectA’, configuration: ‘tests’)

In Stig’s example, you would need a the tests configuration to extends the testRuntime configuration. And would have to have to the add the archive to that confs. E.g.

task jarTests(type: Jar, dependsOn: testClasses) {
    classifier = 'tests'
    from sourceSets.test.output
}
configurations {
    tests {
        dependsOn testCompile
    }
}
artifacts {
    tests jarTests
}

I tried to encapsulate this in the nebula-test-jar plugin: https://github.com/nebula-plugins/nebula-publishing-plugin/blob/master/src/main/groovy/nebula/plugin/publishing/NebulaTestJarPlugin.groovy

Thanks Stig and Justin.

Justin, the description in your answer was correct but the snippet wasn’t quite right. Here is what I ended up with based on your example:

task jarTests(type: Jar, dependsOn: testClasses) {
        classifier = 'tests'
        from sourceSets.test.output
    }
      configurations {
        tests {
            extendsFrom testRuntime
        }
    }
      artifacts {
        tests jarTests
    }