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

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).

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.

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'
}

Exclude dependencies

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

How to give dependecies in multiproject in Gradle and what is the structure?

I have a multi project to be built using Gradle which has a java Project and it'll be dependancy for web Project. When I build with eclipse i have given depencies of javaProj and webProj to webprojectEAR and it works(after deployed).
.ear file needs to be created using single build run whcih has the following content.
- lib
javaProj.jar
- META-INF
- webProj.war
my project structure as follows
- javaProj
build.gradle
- webProj
build.gradle
- webProjEAR
build.gradle
- settings.gradle
I'm trying to run the webProjEAR/build.gradle file and given as dependency as follows in it.
project(':webProjEAR') {
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
}
it failed with error "Could not resolve all dependencies for configuration 'webProjEAR:testRuntime' .when I run build files separatly I am able to create jar and war files.
Please can anyone help me how dependencies should be mentioned in the build files. And, where are the madatory locations to have a build.gradle file.
=== More Information added to the original question from here ===
My build files are as below. I have made the changes Igor Popov had mentioned.
// javaProj/build.gradle
apply plugin: 'java'
repositories {
flatDir { dirs "../local-repo" }
}
sourceSets {
main {
java.srcDir "$projectDir/src"
resources.srcDir "$projectDir/XML"
}
}
jar {
from ('classes/com/nyl/xsl') {
into 'com/nyl/xsl'
}
}
dependencies {
compile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
compile group: 'slf4j-jdk14' , name: 'slf4j-jdk14' , version: '1.5.6'
compile group: 'com.ibm.xml.thinclient_1.0.0' , name: 'com.ibm.xml.thinclient_1.0.0' , version: '1.0.0'
compile group: 'junit', name: 'junit', version: '4.11'
compile group: 'saxon9' , name: 'saxon9'
compile group: 'saxon9-dom' , name: 'saxon9-dom'
compile group: 'xmlunit' , name: 'xmlunit' , version: '1.4'
}
==============================================
// webProj/build.gradle
apply plugin: 'war'
repositories {
flatDir { dirs "../local-repo" }
}
webAppDirName = 'WebContent'
dependencies {
providedCompile group: 'com.ibm.xml' , name: 'com.ibm.xml'
providedCompile group: 'com.ibm.ws.prereq.xdi2' , name: 'com.ibm.ws.prereq.xdi2'
providedCompile group: 'com.ibm.ws.xml.admin.metadata' , name: 'com.ibm.ws.xml.admin.metadata'
providedCompile group: 'guava' , name: 'guava' , version: '11.0.2'
providedCompile group: 'j2ee' , name: 'j2ee'
providedCompile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
providedCompile group: 'slf4j-log4j12' , name: 'slf4j-log4j12' , version: '1.5.6'
}
====================================================
// webProjEAR/build.gradle
apply plugin: 'java'
apply plugin: 'ear'
repositories {
flatDir { dirs "../local-repo" }
}
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
ear {
appDirName 'src/main/app'
libDirName 'APP-INF/lib'
from ('../javaProj/build/libs') {
into 'lib'
}
from ('../webProj/build/libs') {
into '/'
}
}
I would like to know what should contain in the roojProj/build.gradle file. Also like to know anything needs to be changed in the above files. Thanks
The overall structure should be something like:
rootProj
javaProj
build.gradle
webProj
build.gradle
webProjEAR
build.gradle
settings.gradle
build.gradle
The settings.gradle file should contain:
include 'javaProj', 'webProj', 'webProjEAR'
For the webProjEAR/build.gradle you can remove the project(':webProjEAR'). So it should look like:
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
To fix the error you get, you should also post all your dependencies for webProjEAR (if you have others that you didn't include).

Resources