I am migrating ant based project to gradle project. I have to use a set of files or pattern in many tasks which makes me write duplicate code while it can be simply kept in resources and patternset tags in ant. Is there any simpler way like equivalent to resources or patternset in gradle.
<patternset id="pattern.files.to.instrument">
<include name="lib/cat*.jar"/>
<include name="lib/extensions/cat*.jar"/>
<include name="lib/cas*.jar"/>
<include name="bld/internal-lib/cat*.jar"/>
<exclude name="**/*test.jar"/>
<exclude name="**/*.war"/>
</patternset>
<fileset id="fileset.instrument" dir="${uninstrumented.jars.folder}">
<patternset refid="pattern.files.to.instrument"/>
</fileset>
I'm not familiar with Ant, but my first thought on a similar concept in Gradle is a
FileTree
(or aConfigurableFileTree
). You may configure aFileTree
once and (since it implementsFileCollection
) refer to it everywhere where you want to use the files matching the patterns you specified:However, as far as I know,
FileTree
elements are always bound to a root directory, so if you just want to reuse include/exclude patterns, you may take a look atCopySpec
. Elements of typeCopySpec
may be reused using the methodwith
on tasks that implementCopySpec
theirselves (e.g.Copy
,Zip
,Jar
...):