# Remove transitive dependency with classifier and replace with new one without classifier

**URL:** <https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324>\
**Category:** Help/Discuss\
**Created:** [March 20, 2018, 2:28pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324 "2018-03-20T14:28:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [March 20, 2018, 2:28pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/1 "2018-03-20T14:28:45Z")

</div>

Many of our internal libraries using dependency with classifier, something like  
’com.x:artifact:1.0.0:classifier’ and now we get rid of the classifier in the new version.  
But now i need to force gradle to ignore all the transitive dependencies and add just  
’com.x:artifact:2.0.0’

I’m able to remove the dependency globally by

configurations {  
all\*.exclude group: “com.x”, module: “artifact”  
}

But then I can’t add it back. So I need to remove just transition, not direct dependencies.

I tried resolutionStrategy with force and it also doesn’t work.

---

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [April 5, 2018, 4:00pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/2 "2018-04-05T16:00:30Z")

</div>

I tried to use also this:

```
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.name == 'artifact') {
            details.useTarget group: details.requested.group, name: details.requested.name, version: "3.0.0" details.because "We want to use version 3.0.0 without classfier"
        }
    }
}

```

And it also doesn’t help, it looking for the new version, but still with classifier.

---

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [April 5, 2018, 8:45pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/3 "2018-04-05T20:45:23Z")

</div>

```
configurations.all {
    exclude module: "artifact"
    resolutionStrategy.force "com.x:artifact:3.0.0"
}

```

also doesn’t help, exclude is still more strong than force and dependency is completely missing.

---

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [May 23, 2018, 10:32am UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/4 "2018-05-23T10:32:44Z")

</div>

Really no way how to replace one dependency by the same one just without classifier?

---

<div class="post-metadata">

**Author:** ![Svilen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/svilen/32/9107_2.png) [@Svilen](https://discuss.gradle.org/u/Svilen)\
**Post date:** [February 19, 2021, 6:35pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/5 "2021-02-19T18:35:12Z")

</div>

Hi Tomas, I found this way you can manipulate the `classifier` - in my case I wanted to add it (`"linux-x86_64"`), not to remove it:

```
configurations.all {
    resolutionStrategy.eachDependency {
        if (this.requested.module.toString() == "io.netty:netty-transport-native-epoll") {
            @Suppress("UnstableApiUsage")
            this.artifactSelection {
                @Suppress("UnstableApiUsage")
                this.selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "linux-x86_64")
            }
        }
    }
}

```

I’m using Kotlin DSL. Should work with Gradle 6.6 and onward.

Posting here for future reference

---

<div class="post-metadata">

**Author:** ![scraft](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@scraft](https://discuss.gradle.org/u/scraft)\
**Post date:** [September 29, 2021, 2:36pm UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/6 "2021-09-29T14:36:49Z")

</div>

This works, thanks! In my case I needed to remove the classifier, so the syntax ended up like:

```gradle
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.module.toString() == "commons-beanutils:commons-beanutils") {
            details.artifactSelection{
                it.selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, null)
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![lolosiax](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lolosiax/32/11360_2.png) [@lolosiax](https://discuss.gradle.org/u/lolosiax)\
**Post date:** [December 2, 2024, 3:13am UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/7 "2024-12-02T03:13:06Z")

</div>

Wow, thanks, thanks to this Disscuss, I successfully solved the problem of my project being too large after packaging. It’s even 1GB!

```kotlin
dependencies {
    // something omitted ...
    implementation("org.bytedeco:javacv-platform:1.5.11")
}

configurations.runtimeClasspath.get().resolutionStrategy {

    // 只保留 Linux 和 Windows 的 x64 平台。
    val artifacts = listOf(
        "artoolkitplus", "ffmpeg", "flycapture", "javacpp", "leptonica", "libdc1394",
        "libfreenect2", "libfreenect", "librealsense2", "librealsense", "openblas",
        "opencv", "tesseract"
    )
    eachDependency {
        if(requested.group == "org.bytedeco"){
            if (requested.name in artifacts){
                artifactSelection {
                    selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "")
                    selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "windows-x86_64")
                    selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "linux-x86_64")
                }
            }
            else if (requested.name == "videoinput"){
                artifactSelection {
                    selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "")
                    selectArtifact(DependencyArtifact.DEFAULT_TYPE, null, "windows-x86_64")
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [December 2, 2024, 7:50am UTC](https://discuss.gradle.org/t/remove-transitive-dependency-with-classifier-and-replace-with-new-one-without-classifier/26324/8 "2024-12-02T07:50:36Z")

</div>

Sounds more like you (and OP) should use a component metadata rule, not a resolution strategy, even if it also works.
