Test API Dependency not Resolving


I’m trying to use code from another module in my current module’s tests.

My build.gradle.kts contains:


Which contains the MarketCategory.java file with its code.
The test looks like this:

    @DisplayName("Test Market#basePrices")
    public void testMarketPrices() {
         for (MarketCategory c : MarketCategory.values())
             for (String s : c.getItemNames())
                Assertions.assertTrue(Novaconomy.basePrices.containsKey(s), "Missing items in " + c.name() + ": Missing '" + s + "'");

However, when running ./gradlew test, this error is reported:

java.lang.NoClassDefFoundError: us/teaminceptus/novaconomy/api/economy/market/MarketCategory

TestNovaconomy > Test Market#basePrices FAILED
    java.lang.NoClassDefFoundError at TestNovaconomy.java:13
        Caused by: java.lang.ClassNotFoundException at TestNovaconomy.java:13

How can I get gradle to resolve the main sources in api/src/main/java to be resolved in core/src/test/java?
Help is appreciated :slight_smile:

Are you sure this is the first error?
As it is available at compile time and not defined compileOnly, it should also be available at runtime.
But if for example some static initialization throws an exception, this can be displayed as class not found exception too when trying to access the class again.

Otherwise, can you provide an MCVE, or a build --scan of your failing execution?

The MarketCategory.java class is an enum, and the error does not say that it can’t be initialized, so it probably is something with the actual gradle dependencies.

Here’s a Scan done over GitHub Codesaces: https://scans.gradle.com/s/4vmbvobyz4hae

The dependencies are fine.
As you can see at Build Scan™ | Gradle Cloud Services, novaconomy-api is part of the testRuntimeClasspath of novaconomy.