Can a platform BOM be an api dependency?

I’m trying to define a platform BOM as an api dependency of a java-library, but it doesn’t seem to be working. Is this something that’s not supported?

E.g.:

// lib/build.gradle
plugins {
    id "java-library"
}

repositories {
    mavenCentral()
}

dependencies {
    api "net.openhft:chronicle-bom:2.17.465"
    api "net.openhft:chronicle-queue"
}
// dist/build.gradle
plugins {
    id "distribution"
}

repositories {
    mavenCentral()
}

configurations {
    dist {
    }
}

dependencies {
    dist project(":lib")
}

distributions {
    main {
        contents {
            into("lib") {
                from configurations.dist
            }
        }
    }
}

Resulting in the error:

> Task :dist:distTar FAILED
:dist:distTar (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 0.016 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dist:distTar'.
> Could not resolve all files for configuration ':dist:dist'.
   > Could not find net.openhft:chronicle-queue:.
     Required by:
         project :dist > project :lib

It’s as if there was no api for the platform dependency in the lib subproject. If I specify the queue version it works, but that defeats the point of the BOM. To get this to comile I have to make dist also a java and declare the BOM inside the dist configuration as well. Can this be avoided?

Answer to question " Can a platform BOM be an api dependency?": Yes. Absolutely.

But in your case that should not even be needed (you could use implementation), because a distribution should package everything required for running the software (it should use the runtime classpath that includes everything).

One thing you need to ensure is to depend on the BOM as platform:

api platform("net.openhft:chronicle-bom:2.17.465")

Then it is still not working because the Distribution Plugin did not receive enough love recently :disappointed: and we should update the sample in the documentation. The plugin is written in a Java-independent way, but now, if you want to use it to package Java software, it needs to know some more rules to choose the right variants of all projects/components.

Please apply the java-base plugin in addition. Then it should work:

// dist/build.gradle
plugins {
    id "java-base"
    id "distribution"
}

...