简体   繁体   English

Gradle“排除”本地“fileTree”子项目的传递依赖

[英]Gradle 'exclude' local `fileTree` based transitive dependency from sub-project

For some weird reasons, I'm using local filetree based jars in the gradle classpath.由于一些奇怪的原因,我在 gradle 类路径中使用基于本地文件树的 jars。

from sub-module(project), I want to exclude one of the local jar.从子模块(项目)中,我想排除本地 jar 之一。 but I'm missing the syntax for it, can someone provide me correct syntax to exclude the local jar file(s) as a transitive dependency here?但我错过了它的语法,有人可以提供正确的语法来排除本地 jar 文件作为传递依赖项吗?

dependencies {
    implementation(project(":my-simple-project")) {
        exclude fileTree(dir: "../lib/", include: ["axis2-1.7.8/axis2-transport-http-1.7.8.jar"])
    }
   }

OR或者

dependencies {
    implementation(project(":my-simple-project")) {
        exclude files("../lib/axis2-1.7.8/axis2-transport-http-1.7.8.jar"])
    }
   }

I got an error as我收到一个错误

* What went wrong:
A problem occurred evaluating project ':my-simple-project'.
> Could not find method exclude() for arguments [directory '../lib/'] on DefaultProjectDependency{dependencyProject='project ':my-simple-project'', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency.

You can only exclude module dependencies, not file dependencies.您只能排除模块依赖项,不能排除文件依赖项。


If you cannot resolve your dependencies from public repositories like Maven Central or JCenter, you can create a local Maven repository (even inside your project structure) and resolve the files directly from there:如果您无法从 Maven Central 或 JCenter 等公共存储库中解析依赖项,则可以创建本地 Maven 存储库(甚至在您的项目结构中)并直接从那里解析文件:

repositories {
    maven {
        url uri("${projectDir}/lib")
    }
}

dependencies {
    implementation 'org.apache.axis2:axis2-transport-http:1.7.8'
}

Please note, that you must modify the directory structure in your lib folder to match the Maven directory structure (or alternatively define an Ivy repository with a custom structure).请注意,您必须修改lib文件夹中的目录结构以匹配 Maven 目录结构(或者使用自定义结构定义 Ivy 存储库)。

You can exclude nested jar using the following syntax:您可以使用以下语法排除嵌套的 jar:

fileTree(dir: 'lib').exclude {details ->
    (details.file.canonicalPath.contains("axis2-1.7.8")
            && details.file.canonicalPath.contains('axis2-transport-http-1.7.8'))}

OR或者

fileTree(dir: 'lib').exclude { details ->
        details.file.text.contains('axis2-transport-http')
}

Reference: Gradle fileTree exclude all except certain directories参考: Gradle fileTree 排除除某些目录之外的所有目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM