shadow icon indicating copy to clipboard operation
shadow copied to clipboard

Local submodules are not excluded when projects sets version with a `+`

Open chali opened this issue 4 years ago • 1 comments

I have noticed that excludes for local submodule dependencies are not working when version is set and it contains +. I noticed that there is a regex matching which is probably confused by that character. Here is [a sample project] (https://github.com/chali/shadow-jar-project-filtering) Running ./gradlew shadowJar and opening app/build/libs/app-0.7.0+1-all.jar will show that it contains a class from module common which has been excluded. When a version without + is used everything works as expected.

Shadow Version

Shadow version 7.0.0

Gradle Version

Gradle version 7.0.1

Expected Behavior

Local submodule project dependency should be filtered out.

Actual Behavior

Classes from local submodule dependency are present.

Gradle Build Script(s)

The interesting part of build.gradle

subprojects {
    apply plugin: 'java-library'

    version = "0.7.0+1"
}

The interesting part of app/build.gradle

dependencies {
    implementation(project(":common"))
}

shadowJar {
    dependencies {
        exclude(project(":common"))
    }
}

Content of Shadow JAR

jar tf app/build/libs/app-0.7.0+1-all.jar
META-INF/
META-INF/MANIFEST.MF
Hello.class

chali avatar May 19 '21 20:05 chali

As a workaround I used a custom exclude spec just with project name and group:

shadowJar {
    dependencies {
         exclude({
            Dependency dependency = project.dependencies.project(path: ":commons")
            (!dependency.group || it.moduleGroup.matches(dependency.group)) &&
                   (!dependency.name || it.moduleName.matches(dependency.name))
         })
    }
}

chali avatar May 19 '21 21:05 chali