Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid+Gradle: list directories into a file
    primarykey
    data
    text
    <p>I'm trying to convert a task I have in an ANT build to Gradle:</p> <pre><code>&lt;target name="index-assets" depends="copy-assets"&gt; &lt;path id="assets.path"&gt; &lt;!-- contexts (and surplus) --&gt; &lt;dirset id="assets.dirset" dir="assets/" defaultexcludes="yes"/&gt; &lt;!-- assets --&gt; &lt;fileset id="assets.fileset" dir="assets/" includes="**" excludes="asset.index" defaultexcludes="yes"/&gt; &lt;/path&gt; &lt;pathconvert pathsep="${line.separator}" property="assets" refid="assets.path" dirsep="/"&gt; &lt;mapper&gt; &lt;globmapper from="${basedir}/assets/*" to="*" handledirsep="yes"/&gt; &lt;/mapper&gt; &lt;/pathconvert&gt; &lt;echo file="assets/asset.index"&gt;${assets}&lt;/echo&gt; &lt;/target&gt; &lt;target name="-pre-build" depends="index-assets"/&gt; </code></pre> <p>I guess I'm still not completely grasping basic Gradle concepts, but here's what I tried:<br/></p> <pre><code>task indexAssets &lt;&lt; { def assets = file("assets") def contexts = files(assets) inputs.file(assets) outputs.file("assets/assets-gradle.index") def tree = fileTree(dir: 'assets', include: ['**/*'], exclude: ['**/.svn/**', 'asset.index']) contexts.collect { relativePath(it) }.sort().each { println it } tree.collect { relativePath(it) }.sort().each { println it } } </code></pre> <ol> <li>The tree is fine, but contains only file (leaf) paths<br/></li> <li>I just can't seem to get the simple clean list of directories (contexts) though. I tried several other variants (tree, include/exclude), but I either get a single file in that directory, the directory name itself or nothing. I just want a simple list of directories found in the 'assets' dir.</li> <li><p>For now I'm just trying to print the paths, but I'd also like to know the proper way to later write these into a file (like ANT's echo file). <br/> <br/> <strong>Update:</strong><br/> This groovy snippet seems to do that part (+ svn filter), but I'd rather find a more "Gradley" way of doing this task. It runs in a context of a build variant later as a pre-build dependency. (NOTE: I had to specify the 'Project' as part of the path in this hack since I guess I'm not in that project context for the task?)<br/></p> <pre><code>def list = [] def dir = new File("Project/assets") dir.eachDirMatch (~/^(?!\.svn).*/) { file -&gt; list &lt;&lt; file } list.each { println it.name } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload