Skip to content

shadowJar fails with "Cannot expand ZIP" when dependency includes non-existent class directory #1975

@ln-e

Description

@ln-e

Expected and Results

When a project dependency includes a class output directory that does not exist (e.g., build/classes/java/api from a custom source set with no Java sources), shadowJar should gracefully skip it or treat it as an empty directory, rather than failing.

Actual behavior
shadowJar fails with:
Cannot expand ZIP '/path/to/project/build/classes/java/api' as it does not exist.

Related environment and versions

No response

Reproduction steps

  1. Create a multi-module Gradle project with a custom api source set:
  // root build.gradle.kts
  subprojects {
      sourceSets {
          val api by creating
          val main by getting {
              compileClasspath += api.output
              runtimeClasspath += api.output
          }
      }
  }
  1. In one of the submodules, apply the Shadow plugin and have Kotlin-only sources in the api source set (no Java files under src/api/java/).
  2. Run ./gradlew :module:shadowJar.
  3. The task fails because build/classes/java/api is included in runtimeClasspath via api.output, but the directory was never created since there are no Java sources to compile in that source set.

Anything else?

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions