Help understanding publishing artifact, plain vs. bootable, and testImplementation,

I spent a chunk of time investigating java test fixtures plugin… I could not get it to do what I wanted and got a lot of errors - the docs are not the best in describing publishing your own fixtures or I am just not that experienced with gradle to understand it + not finding a lot of examples online.

Regardless I finally did figure out an easy solution to my problem in case this helps anyone else. I concluded from different readings that the gradle spring boot plugin is what causes the plain and boot jars to be created. I was trying to force the plain jar to have the same content as the boot jar and failing or trying to pick the boot jar when using testImplementation without any success…

I found archiveClassifier and wondered if that could be the answer and it was. Below is how I got the contents of the jar file to be test/resources and then how I referenced the published dependency in the other project in order to use the shared test/resources…

Common Project build.gradle

task createTestResourcesJar(type: Jar) {
    from sourceSets.test.resources
    archiveClassifier = 'test' // causes -test.jar to be created
}

artifacts {
    archives createTestResourcesJar
}

publishing {
    publications {
        // main common publish
        mavenJava(MavenPublication) {
            groupId = 'com.foobar'
            artifactId = 'foobar-common'
            from components.java
        }
       // test resources publish
       testResources(MavenPublication) {
           groupId = 'com.foobar'
          artifactId = 'common-test-resources'
          version = "0.0.1-SNAPSHOT"
          from components.java
          artifact createTestResourcesJar
       }
...

Downstream Project’s build.gradle

testImplementation 'com.foobar:common-test-resources:0.0.1-SNAPSHOT:test' // references specific -test.jar