Scala project with api dependencies

I have a scala project which uses the old compile dependency configuration. I want to migrate them to api and implementation scopes. The current gradle project provides a fat-jar with all compile dependecies.
I tried to move those to api but without success. I tried to change the composeFatJar task from configurations.compile.collect to configurations.api.collect but api is not accessible. Then I tried to use java-library and java-library-distribution and played around with them, plugin but all I get out is a jar that only contians the compiled sources without the api libraries or a jar containing all libraries including the ones from the implementation section.

Here’s the original gradle script. Can someone please give me a hint?

plugins {
    id 'scala'
//    id 'java-library'
//    id 'java-library-distribution'
    id 'maven-publish'

group = 'xyz'
version = '1.0.0-SNAPSHOT'

repositories {

ext {
    nexus_user = System.getenv('NEXUS_USER')
    nexus_password = System.getenv('NEXUS_PASSWORD')

dependencies {
    testImplementation  "org.scalatest:scalatest_${scalaVersionShort}:3.0.5"

    implementation   (

task composeFatJar(type: Jar) {
    zip64 = true
    manifest {
        attributes 'Main-Class': 'xyz'
    archiveFileName = + '-all-dep.jar'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar

task copyFatJar(type: Copy) {
    from composeFatJar
    into "$buildDir/toArchive/lib"

task copyReadme(type: Copy) {
    from ""
    into "$buildDir/toArchive/"

task packageArchive(type: Tar) {
    dependsOn {tasks.findAll { task ->'copy') } }
    compression = Compression.GZIP
    from "$buildDir/toArchive"

task testScala(dependsOn: ['testClasses'], type: JavaExec) {
    main = ''
    args = ['-R', 'build/classes/scala/test','-o']
    classpath = sourceSets.test.runtimeClasspath

publishing {
    publications {
        myPublication(MavenPublication) {
            artifact packageArchive
            artifact composeFatJar
    repositories {
        maven {
            def releasesRepoUrl = "https://..."
            def snapshotsRepoUrl = "https://..."
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            credentials {
                username "${nexus_user}"
                password "${nexus_password}"

Does anybody have an idea?

You won’t have api without applying the java-library plugin, and you don’t want to use api directly in the composeFatJar task. You probably should use runtimeClasspath here, but could possibly use the other blue configuration or one you create, if you need something special. See Java Library Configurations.