0

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.

drue
  • 21
  • 6
  • 1
    Try changing `from(components["kotlin"])` to `from(components["java"])`, which matches [the example in the docs](https://docs.gradle.org/7.6/userguide/java_testing.html#publishing_test_fixtures). – aSemy Feb 07 '23 at 20:24
  • @aSemy that sure did the trick! Thank you. I'll accept it if you post it as an answer. If anyone is able to elaborate on why using `from(components["kotlin"])` works to produce the correct jar files (I have verified this) for the main package but not the test fixtures, please do so. I can't remember the exact reason why I went with `"kotlin"` to begin with, but I assume it was due to the source root folder being names kotlin and not java. However, this does not seem to have an impact. – drue Feb 08 '23 at 10:02

0 Answers0