Capture standard out from custom ant task


(Stefan Marklund) #1

Hello all,

I have a custom Ant task I want to reuse in my Gradle build.

It logs progress/information on standard out (System.out.println).

I want that output without having to change the Gradle log level on the commandline.

In the Logging chapter (Chapter 18) of the userguide it says that the default capture level of standard out is QUIET which has priority over LIFECYCLE which is the default Gradle log output level. So I should be seeing the output on a standard Gradle invocation then?

But I cant get the output without specifying the -i flag to Gradle.

Examples:

s@smarkyone:~/projects/b/DevelopmentPlatform/Base/Base_BIGen$ gr hello
:DevelopmentPlatform:Base:Base_BIGen:hello
  BUILD SUCCESSFUL
  Total time: 2.826 secs
    s@smarkyone:~/projects/b/DevelopmentPlatform/Base/Base_BIGen$ gr hello -i
Selected primary task 'hello'
Tasks to be executed: [task ':DevelopmentPlatform:Base:Base_BIGen:hello']
:DevelopmentPlatform:Base:Base_BIGen:hello
Task ':DevelopmentPlatform:Base:Base_BIGen:hello' has not declared any outputs, assuming that it is out-of-date.
[ant:hello] Hello from HelloTask
  BUILD SUCCESSFUL
  Total time: 1.812 secs

Hello task used:

HelloTask.java:
  import org.apache.tools.ant.taskdefs.Java;
  public class HelloTask extends Java {
    public void execute() throws org.apache.tools.ant.BuildException {
        System.out.println("Hello from HelloTask");
    }
  }

Gradle task definition:

task hello() << {
    ant.taskdef( parameters )
     ant.hello()
}

I have been testing different permutations of setting capture- and log level on the logging object on the task object without success.

Have I missed something cruicial or is the output not being printed as expected as per the documentation?

Any help is much appreciated.

Thank you in advance, Stefan


(Szczepan Faber) #2

I have been testing different permutations of setting capture- and log level on the logging object on the task object without success.

Can you paste code showing us how you attempted to configure the logging capturing on the task level?