How to display the order of task executing by 'println'?

I’m using gradle-8.1.1-src and I wonder how to get the task name when touched in the executePlan.
I know that the --profile command will generate a profile and show the task order, but I want to get the order in logging and compare them.
Thanks for your help :smiling_face_with_tear:

If you run with --console=plain or --console=verbose you should get all task names logged. It’s just the rich console that does not show task names unless there is some output except for in the progress message.

OK, and I have an another problem that a project can be built by gradle-5.6.4, but when I use gradle-8.1.1, it will print wrong like:

  • Where:
    Build file ‘/home/Apps/android-PictureInPicture-master/app/build.gradle’ line: 1
  • What went wrong:
    A problem occurred evaluating project ‘:app’.
    org/gradle/initialization/BuildCompletionListener

I wonder whether the new version can cover the old version

You cannot simply run a build designed for an old version with a new version.
That is why each and every project even if tiny should include the 4 wrapper files.
Those then define which Gradle version to use to execute the build and to execute the build you only need a compatible Java version, but never an installed Gradle version.

If you want to update the Gradle version, read the release notes and the upgrade notes which contain breaking changes. And then I usually recommend to update to the latest 5.x version, update all used plugins to the latest compatible version, then fix all deprecation warnings. If a build runs without deprecation warnings in the latest minor version, it should usually be compatible with the next minor version except for exceptions. So then update to the latest 6.x and repeat until you are at the target version.

how to use the “log.info()” function, I see the method that use slf4j log.info() to print the message in log, but it shows the error:


so I’d like to know how to success.

Don’t try to use fields that do not exist?
Did you ever program in Java before?
TaskExecution has a LOGGER field with which you could log,
AbstractTask has a logger field with which you could log.
None of the two has a log field that you try to use and your error message is telling you that.

1 Like

ah sorry, I’m exactlly a rookie of Java. Now I add a “LOGGER.info(“here!!!”);” in TaskExecution.java, with function executeAction(), but when I run the command :

./gradlew assemble --no-configuration-cache

there isn’t any “here!!!” appear in the log. So I’d like to know whether the gradle will touch the function executeAction() when executing tasks.

Info logs are only shown with -i / --info or higher.

1 Like

Besides that a simple tasks.configureEach { doFirst { logger.info("here!!!") } } would probably be much easier than to compile a whole own Gradle distribution just to add that log line. :smiley:

2 Likes

yeah, I get the log I want! Thank you for your helpful solution!

1 Like

And now another question is that I get the log text by -i >1.txt and the build report by --profile, with the num of --max-workers is 1, but the order of task executing is different. The order of log might be:

Tasks to be executed: [task ‘:compileJava’, task ‘:processResources’, task ‘:classes’, task ‘:jar’, task ‘:assemble’, task ‘:generator:compileJava’, task ‘:generator:processResources’, task ‘:generator:classes’, task ‘:generator:jar’, task ‘:clients:processMessages’, task ‘:clients:compileJava’, task ‘:clients:processResources’,

And the order of report might be:

So,which is the actually executing order

Probably the second one.
But I don’t know if that is guaranteed, never used --profile.
If you want a representation where it is guaranteed, use a build --scan.

What do you actually try to achieve anyway?

I just try to find the detailed location in source code that create the TaskGraph and put the tasks to execute one by one. If I could add something to print the TaskName with the same order of tasks actually executing, that means I find the method of how gradle dispatch the tasks, is it practicable?

What do you mean by “put the tasks to execute one by one.”?
You want to make them not run in parallel?
Why should you want to do that?
And if so, why would --max-workers 1 not be sufficient?

Again, what do you try to achieve?

1 Like

uh sorry I don’t express exactly, I’d like to find the detailed source code where the gradle get the tasks in TaskGraph and execute the tasks with the order managed by TaskGraph.

But I suspect an XY problem. :slight_smile:
I’m still curious what you want to achieve in the end, i.e. why you search for that point in the code.

Maybe compare gradle and makefile when they compile a project in parallel, what is the difference of dispatch method, and explore if there’s any optimization space :smiling_face_with_tear:

But why do you need that spot in the code for this?
What do you want to achieve there?

Hello,
As per me to fetch the task name when executed in executePlan, you can log task order directly for comparison. This avoids relying solely on --profile, providing clear insights into task execution sequence and enabling effective build process optimization.
Thanks

1 Like