Hey there,
I’ve been working on migrating a project’s build system from Ant to Gradle. So far, I’ve faced no issues in the migration except that there’s seems no way to run a task from another task inside a loop. So, I need some help to convert the following set* of Ant targets into Gradle task:
This requires that the class dirs are available at configuration time which is probably not the case. Do you know the class dirs by another means? Ie is there another way to know the class dirs instead of file(ClassesDir).listFiles()
There are a couple of tasks that run before this one, and the ClassesDir is generated by one of those tasks.
OK, so the task which generates the ClassesDir knows which subfolders to create (and ultimately which jars to create). Can you use the same information to determine the jar tasks (instead of driving everything from the class directory list which is empty in the configuration phase)
Can you please give me an example of how to do that? Like, how to get information from another task? Sorry if that question sounds stupid and is too basic. I’m quite new to Gradle.
PS: The task that runs before the jarAll task basically executes a JAR file that generate those files.
Just by looking at your sources, is there a way to know which class directories will be produced by your ant build? Eg is the list configured in an xml file? Is it determined by some java source directories?
You should use this same logic to drive the jar task creation, not the classes directories (since the classes directories don’t exist at configuration time)
The class directories contain the .class files as well as the libraries used to compile the Java source files. There can be several packages in the source directory and each of these packages need to be converted in separate JARs for the further processes to work properly. And that is why I need to run the jar task in a loop to JAR all the complied packages in separate JAR files.
I hope I explained it well.
Yes, in the Java source I have the same directories as compiled class directory. For example, if I have a Java file in format like - com/myJava/file.java then the compiled class directory would be - com.myJava/com/myJava/file.class
Isn’t it the same? Anyways, my main question was how to run a task inside a loop, which I guess you’ve already answered.
BTW, can we run multiple tasks this way? I mean can I have multiple tasks inside a loop? Also, is there anything else you’d like to tell me regarding this?
Well, there’s nothing else I could provide. Like I said, I tried running the task (jarAll) directly, as well as depending another task on it, but it didn’t worked. The build is successful, but there are no traces of the task, which clearly shows that the task was not run. Also, no jar was created.