Same package from two jar (ambiguity)


(devendra singh) #1

Hi,

We are using two jar files which contain a similar package.due to which our build is getting failed.
is there any way to exclude the package from one of the jar file.

Thanks in advance
Devendra


(uklance) #2

See here for an example which creates a new jar by removing some classes and depends on the “tweaked” jar


(devendra singh) #3

I am trying the below code but “FileVisitDetails” is not resolving. i imported the excat package but the
FileVisitDetails is not resolveing. nor even in import statement.

task tweakCommonsConfig(type:Jar) {
def classList = []
fileTree(‘src/main/java’).matching {
include ‘org/apache/commons/**/*.java’
}.visit { FileVisitDetails fvd ->
classList << fvd.relativePath.pathString.replace(’.java’, ‘.class’)
}
from zipTree(configurations.commonsConfig.singleFile).matching {
exclude classList
}
destinationDir buildDir
archiveName ‘tweaked-commons-config.jar’
}


(uklance) #4

You won’t need the classList calculation in that example. You can just do the following to exclude a package

exclude 'foo/bar/**' 

For completeness, here’s the FileVisitDetails interface

https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileVisitDetails.html


(devendra singh) #5

exclude keyword can exclude the transitive dependencies only. correct me if i am wrong. we have package a similar package in two of our jar and we want to exclude a particular one.


(uklance) #6

I don’t think you’ve understood the script. It’s creating a brand new jar from an existing jar and excluding a couple of classes