Exclude dependencies - gradle

I want to exclude dependencies from a dependency :
dependencies {
...
implementation "org.springframework.security:spring-security-web:$springSecurityVersion" {
exclude "org.springframework:spring-core:$springSecurityVersion"
exclude "org.springframework:spring-beans:$springSecurityVersion"
exclude "org.springframework:spring-context:$springSecurityVersion"
exclude "org.springframework:spring-web:$springSecurityVersion"
}
...
}
I tried a couple of options by changing the syntax sugar but in vain.
Updated Exception :
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.1-bin.zip'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsume
...
Apart from that one more line that I see that could be useful is
Could not find method
org.springframework.security:spring-security-web:5.0.4.RELEASE() for
arguments
[build_8wp04892dra2g2ruliafngaad$_run_closure3$_closure5#28d49bbc] on
object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Did you try this syntax, without specifying the version :
implementation ("org.springframework.security:spring-security-web:$springSecurityVersion") {
exclude group: 'org.springframework', module: 'spring-core'
exclude group: 'org.springframework', module: 'spring-beans'
exclude group: 'org.springframework', module: 'spring-context'
exclude group: 'org.springframework', module: 'spring-web'
}
edit : Delete your .gradle directory in your home directory and try again
edit2 : answer's fixed, thanks to op's comment

Related

Exclude package from jar in Gradle 6.4.1

I am using Gradle 6.4.1 and i am getting conflict for package com.jayway.jsonpath in org.apache.drill.exec:drill-jdbc-all:1.18.0 and spring-boot-starter-data-jpa.
So I want to exclude com.jayway.jsonpath package from drill-jdbc-all.jar
compile ('org.apache.drill.exec:drill-jdbc-all:1.18.0') {
exclude group: 'com.jayway.jsonpath'
exclude module: 'json-path'
}
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
Even tried this
configurations {
all {
compile.exclude module: 'com.jayway.jsonpath'
}
}
But still its showing
The class hierarchy was loaded from the following locations:
com.jayway.jsonpath.spi.mapper.JacksonMappingProvider: file:/Users/abc/.gradle/caches/modules-2/files-2.1/org.apache.drill.exec/drill-jdbc-all/1.18.0/6a0b608238f4a431684cd73d132d7467bc2c3967/drill-jdbc-all-1.18.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.jayway.jsonpath.spi.mapper.JacksonMappingProvider
Per the Excluding transitive dependencies section of the 6.4.1 docs, give this a try:
dependencies {
...
implementation('org.apache.drill.exec:drill-jdbc-all:1.18.0') {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
...
}

What's the different between all*.exclude and all.exclude in configurations.all

I want to know what exactly different between all*.exclude and all.exclude in configurations.all when you want to exclude dependencies
configurations.all {
all.exclude
all*.exclude group: 'org.json', module: 'json'
}
The correct syntax is:
Using the all method
configurations.all {
exclude group: 'org.json', module: 'json'
}
OR
Using the all property
configurations {
all*.exclude(group: 'org.json', module: 'json')
}
The all property holds a list of all configuration objects within the project configurations.
If you want to see what it actually it contains you can do:
println configurations.all.names
OR
println configurations.all*.name
And the syntax *. is a groovy specific operator called the spread operator. You can read how that works to understand why it worked here.

What does this "all*.exclude" means in Gradle transitive dependency?

I wonder what does "all*.exclude" mean in Gradle transitive dependency ?
configurations {
compile.exclude group: 'org.hamcrest', module: 'hamcrest-core'
all*.exclude group: 'org.mockito', module: 'mockito-all'
}
Is "all*.exclude" in the code above syntax of Gradle or some else.
In this context, all*. refers to all configurations ...
and it applies exclude group: 'org.mockito', module: 'mockito-all' to all of them.
The all*. syntax is the short-handed notation of:
configurations {
all.collect { configuration ->
configuration.exclude group: 'org.mockito', module: 'mockito-all'
}
}
The *. syntax is called "spread-dot operator", which is a Groovy syntax (see paragraph 8.1).

Could not find method exclude() for arguments on object of type org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency

I used to have
implementation(group: "com.domain.package", name: "lib-name", version: "$ver") {
exclude group: 'com.android.support'
exclude group: 'com.squareup.okhttp3'
exclude group: 'com.google.dagger'
}
When I import as aar
implementation (files('libs/lib-name.aar')) {
exclude group: 'com.android.support'
exclude group: 'com.squareup.okhttp3'
exclude group: 'com.google.dagger'
}
I got the following error.
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method exclude() for arguments [{group=org.apache.commons}] on object of type
org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency.
Wonder what went wrong?
Note: I have check on Could not find method exclude() for arguments [{module=support-v4}], which ensure the extra parenthesis is there, that I have done. But it is not helping.
the problem might be the parenthesis location:
try:
implementation (files('libs/lib-name.aar'), {
exclude group: 'com.android.support'
exclude group: 'com.squareup.okhttp3'
exclude group: 'com.google.dagger'
})
in step of
implementation (files('libs/lib-name.aar')) {
exclude group: 'com.android.support'
exclude group: 'com.squareup.okhttp3'
exclude group: 'com.google.dagger'
}

How can I exclude from Gradle dependency lists after the fact?

This is for a Maven-to-Gradle build conversion on a large build. Think Rodan, Ghidora, Godzilla, etc. Yeah. That big.
Given a dependency that looks like this:
ext.jbossBom = [ ... ]// This is in the root project.
compile (rootProject.ext.jbossBom) //This is not in the root project
How can I exclude items from the above? I've tried variants of:
compile (rootProject.ext.jbossBom) {
exclude group: "some.group", module: "some.module"
}
jbossBom is a collection. Remove the element your want to eliminate:
compile (rootProject.ext.jbossBom.findAll{ !it.startsWith('some.group')})
To exclude a certain transitive dependency globally(irrespective of which dependency brings it in), you can do:
configurations {
compile.exclude group: 'commons-math3', module: 'commons-math3'
compile.exclude group: 'commons-pool2', module: 'commons-pool2'
}
To exclude a specific transitive dependency from each of the contents of jbossBom, you can do:
dependencies{
jbossBom.each{
compile (it){exclude group:'foo', module:'bar'}
}
}

Resources