Publishing test fixtures with submodules, gradle

725 views Asked by At

I have been looking around for a way to include test fixtures in my gradle publications. https://developer.android.com/studio/publish-library/configure-test-fixtures#kts suggests that it should work automatically so long as the project name is set correctly, which I have done in the settings.gradle file. This seems to solve the issue in the case of https://github.com/slackhq/EitherNet/issues/44.

For context, my project is built with several sub modules and I have defined a custom publication for each (I suspect this is the clue to the issue) as shown here:

subprojects {
    // ... some repos and unimportant plugin applications

    tasks {
        register("prepareKotlinBuildScriptModel") {}

        withType<BootJar> {
            enabled = false // this is enabled in the jar I wish to be bootable
        }

        withType<Test> {
            useJUnitPlatform()
        }

        getByName<Jar>("jar") {
            enabled = true
            archiveClassifier.set("") 
        }

    }

    publishing {
        publications {
            create<MavenPublication>(project.name) {
                version = projectVersion
                artifactId = tasks.jar.get().archiveBaseName.get()
                groupId = "${projectGroup}.${rootProject.name}"

                from(components["kotlin"])
            }
        }
    }

For ref, this is currently what my module structure and build.gradle looks like for the module in question:

module structure

plugins {
    id("java-test-fixtures")
    id("java-library")
}

dependencies {
    testFixturesApi(project(":model"))
    ... unrelated stuff

The test fixtures work fine as internal dependencies in the project itself, but they do not get published so that they can be used in external projects.

So my question is if there is a way to bake the test fixtures into my submodule jars so they can be used in external projects?

Any input would be highly appreciated.

Tried, expected, result: Publishing to local repo, expected the test fixtures to be bundled, they were not.

0

There are 0 answers