Gradle排除依赖关系中的特定文件
我想知道是否有排除特定的文件,这是在一个依赖(而不是传递依赖),被下载。
我正在从Ant + Ivy切换到Gradle,而这一切都是在Ivy之前完成的。 我问,因为我有一个单独的依赖关系,其中包含Artifactory中的许多已编译的wsdl jar,但我不想下载依赖关系中的所有jar。
在常春藤它被设置为:
这6个工件被发布到Artifactory中的目录repo / dep.location / example / 7.3 / jar。
<publications> <artifact name="foo-1-0" type="jar" /> <artifact name="foo-1-0-async" type="jar" /> <artifact name="foo-1-0-xml" type="jar" /> <artifact name="bar-1-0" type="jar" /> <artifact name="bar-1-0-async" type="jar" /> <artifact name="bar-1-0-xml" type="jar" /> </publications>
这是我如何检索六个文物中的两个。
<dependency org="dep.location" name="example" rev="7.3" conf="compile,runtime"> <include name="foo-1-0-async"/> <include name="foo-1-0-xml"/> </dependency>
目前,如果我尝试在Gradle中执行类似的操作,则会忽略排除项,并且下载所有六个工件。
compile (group:"dep.location", name:"example", version:"7.3") { exclude module:'foo-1-0-xml' exclude module:'bar-1-0' exclude module:'bar-1-0-async' exclude module:'bar-1-0-xml' }
我正在使用Gradle版本1.8。
- Maven:如何覆盖库添加的依赖项
- 来自itext的jasper-reports中的依赖性错误
- 在package.json中查找未使用的npm包
- Python中的循环导入依赖
- 为什么npm install说我有未满足的依赖关系?
我不认为Gradle有任何内置的支持来完成这个任务,但是你可以自己从classpath中清除工件。
受到Gradle论坛上的这个线索的启发,我想出了这个:
// The artifacts we don't want, dependency as key and artifacts as values def unwantedArtifacts = [ "dep.location:example": [ "foo-1-0-xml", "bar-1-0", "bar-1-0-async", "bar-1-0-xml"], ] // Collect the files that should be excluded from the classpath def excludedFiles = configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll { def moduleId = it.moduleVersion.id def moduleString = "${moduleId.group}:${moduleId.name}:${moduleId.version}" // Construct the dependecy string // Get the artifacts (if any) we should remove from this dependency and check if this artifact is in there it.name in (unwantedArtifacts.find { key, value -> moduleString.startsWith key }?.value) }*.file // Remove the files from the classpath sourceSets { main { compileClasspath -= files(excludedFiles) } test { compileClasspath -= files(excludedFiles) } }
请注意,Gradle可能仍会下载这些文件并caching它们,但它们不应该放在你的类path中。
我不确定这是否是你想要的,但是由于我们使用的是Spring Boot和Wildfly,我们必须从spring引导标准包中删除tomcat-starter模块,它看起来与你所做的非常相似。 但是,我们的代码指出:
configurations { compile.exclude module: "spring-boot-starter-tomcat" }
我没有检查相应的jar是不是下载或只是不在类path,我知道,但它不被使用了。
- 我必须手动卸载所有依赖的gem?
- 你知道mvnrepository.com的maven profile吗?
- HintPath VS Visual Studio中的ReferencePath
- 如何更改Meteor加载Javascript文件的顺序?
- 警告:与依赖冲突com.android.support:support-annotations'
- Xcode:在每个修改源代码的构build之前运行脚本
- node.js TypeError:path必须是绝对path或指定根pathres.sendFile
- 复制本地如何工作? log4net.dll不被复制到MyProject输出目录
- 从编码风格的angular度来看,循环类的依赖性是不是很糟糕?