英文:
How to create a collection of file collections in gradle?
问题
我正在将一个蚂蚁项目迁移到 Gradle 项目。我有一组文件集合,这些文件将作为多个任务的输入。在蚂蚁中可以使用<union>来实现这一点。
<zipfileset id="zipfileset1" src="C:/reporter/servlet/reporter.war">
<include name="WEB-INF/classes/**/*.class"/>
<exclude name="WEB-INF/classes/**/*_jsp*.class"/>
</zipfileset>
<fileset id="fileset1" dir="C:/lib">
<include name="test*.jar"/>
</fileset>
<union id="resources.reports.lib">
<fileset refid="fileset1"/>
<fileset id="fileset2" dir="C:/adaptors/lib">
<include name="com*.jar"/>
</fileset>
<zipfileset refid="zipfileset1"/>
</union>
在 Gradle 中是否有与蚂蚁中的<union>等效的方法呢?
英文:
I am working on moving an ant project to gradle project. I have a set of file collection where to be used in as input for several tasks. This is possible in ant with <union>.
<zipfileset id="zipfileset1" src="C:/reporter/servlet/reporter.war">
<include name="WEB-INF/classes/**/*.class"/>
<exclude name="WEB-INF/classes/**/*_jsp*.class"/>
</zipfileset>
<fileset id="fileset1" dir="C:/lib">
<include name="test*.jar"/>
</fileset>
<union id="resources.reports.lib">
<fileset refid="fileset1"/>
<fileset id="fileset2" dir="C:/adaptors/lib">
<include name="com*.jar"/>
</fileset>
<zipfileset refid="zipfileset1"/>
</union>
Is there any method in gradle equivalent to "union" in ant.
答案1
得分: 3
这里有一个工作示例链接。
注意,Gradle与Ant有紧密集成(见此处),因此一个选项是从Ant代码直接迁移。例如:
// 注意:这里使用本地目录而不是Windows路径(例如C:\lib)
ant.zipfileset(id: "zipfileset1", src: "c_reporter/servlet/reporter.war") {
include(name: "WEB-INF/classes/**/*.class")
exclude(name: "WEB-INF/classes/**/*_jsp*.class")
}
ant.fileset(id: "fileset1", dir: "c_lib") {
include(name: "test*.jar")
}
ant.union(id: "resources.reports.lib") {
fileset(refid: "fileset1")
fileset(id: "fileset2", dir: "c_adaptors/lib") {
include(name: "com*.jar")
}
zipfileset(refid: "zipfileset1")
}
根据评论,另一种替代且更符合Gradle风格的方法是:(在上面的链接中也有示例)
project.ext.zipFiles1 =
zipTree("${projectDir}/c_reporter/servlet/reporter.war").matching {
include 'WEB-INF/classes/**/*.class'
exclude 'WEB-INF/classes/**/*_jsp.class'
}
project.ext.files1 =
fileTree("${projectDir}/c_lib").matching {
include 'test*.jar'
}
project.ext.files2 =
fileTree("${projectDir}/c_adaptors/lib").matching {
include 'com*.jar'
}
project.ext.allFiles =
project.ext.zipFiles1.plus(project.ext.files1)
.plus(project.ext.files2)
英文:
There is a working example here
Note that Gradle has tight integration with Ant (see here) so one option is a straight migration from the Ant code. For example:
// NOTE: this uses local dirs instead of Windows paths (e.g. C:\lib)
ant.zipfileset(id:"zipfileset1", src:"c_reporter/servlet/reporter.war") {
include(name:"WEB-INF/classes/**/*.class")
exclude(name:"WEB-INF/classes/**/*_jsp*.class")
}
ant.fileset(id:"fileset1", dir:"c_lib") {
include(name:"test*.jar")
}
ant.union(id:"resources.reports.lib") {
fileset(refid:"fileset1")
fileset(id:"fileset2", dir:"c_adaptors/lib") {
include(name:"com*.jar")
}
zipfileset(refid:"zipfileset1")
}
Per comment, an alternative -- and more Gradle-esque approach -- is: (also illustrated in the link above)
project.ext.zipFiles1 =
zipTree("${projectDir}/c_reporter/servlet/reporter.war").matching {
include 'WEB-INF/classes/**/*.class'
exclude 'WEB-INF/classes/**/*_jsp.class'
}
project.ext.files1 =
fileTree("${projectDir}/c_lib").matching {
include 'test*.jar'
}
project.ext.files2 =
fileTree("${projectDir}/c_adaptors/lib").matching {
include 'com*.jar'
}
project.ext.allFiles =
project.ext.zipFiles1.plus(project.ext.files1)
.plus(project.ext.files2)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论