'Java module dependencies and testImplementation dependencies

I apologise if this is a duplicate - a link to another answer would be great, but I am having difficulty knowing what to search for.

I am building a library (kotlin, but I can jump between kotlin and java terminology quite happily). In this library I want the unit tests to depend upon an external library. I have added a line to build.gradle.kts

testImplementation("library-group:library-name:0.0.13")

And it all compiles fine, I can publish the library to maven-local, and use it. But when I want to run the tests I get an IllegalAccessException because my module info.java does not specify a dependency upon the library that the tests depend upon.

I know it can be done - the test code depends upon JUnit, but that is not declared in module info. My guess is that there is a fairly simple incantation to add to build.gradle.kts but I do not know what to search for..... any help gratefully received.

Edit1: The library that I depend upon at test time is modular. The problem is that when I run the tests that access classes in library-group:library-name these are not present. I get an IllegalAccess exception as the required class is not present. It is as if I need two moduleinfo.java files, one for test and one for production. /Edit1

Some relevant parts of build.gradle.kts:

plugins {
    // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
    id("org.jetbrains.kotlin.jvm") version "1.5.31"

    // Apply the java-library plugin for API and implementation separation.
    `java-library`
    `maven-publish`

    // https://plugins.gradle.org/plugin/org.jlleitschuh.gradle.ktlint
    id("org.jlleitschuh.gradle.ktlint") version "10.1.0"

    // https://github.com/java9-modularity/gradle-modules-plugin/blob/master/test-project-kotlin/build.gradle.kts
    id("org.javamodularity.moduleplugin") version "1.8.9"
}

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

    // Use the Kotlin JDK 8 standard library.
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    testImplementation(kotlin("test"))

    // https://logging.apache.org/log4j/kotlin/index.html
    // https://github.com/apache/logging-log4j-kotlin
    implementation("org.apache.logging.log4j:log4j-api-kotlin:1.0.0")
    implementation("org.apache.logging.log4j:log4j-api:2.11.1")
    implementation("org.apache.logging.log4j:log4j-core:2.11.1")

    testImplementation("library-group:library-name:0.0.13")
}

tasks.test { useJUnitPlatform() }
kotlin { explicitApi = ExplicitApiMode.Strict }
tasks.compileKotlin { kotlinOptions.allWarningsAsErrors = true }




Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source