How to extend Test class to create my own custom task


(nangonda patil) #1

When we create a custom task by extending DefaultTask, the custom task is available to build script. But, same custom task if we create extending Test , it won’t work. e.g: custom Tasks as below:

public class MyTestType1 extends DefaultTask { }

public class MyTestType2 extends Test { }

Now, if in build file if we have task as below:

task myTask (type : MyTestType1) { } — This works task myTask (type : MyTestType2) { } — This won’t work

Error’s out as below: > Could not create task of type 'MyTestType2 '.

Please let us know if we are missing anything here…


(Peter Niederwieser) #2

You’d have to at least include the full error message. In any case, most of Gradle’s built-in task types aren’t designed to be subclassed.


(nangonda patil) #3

Have pasted stack trace on gist: https://gist.github.com/anonymous/ddf432760d1563a5ddb3


(Peter Niederwieser) #4

Sounds like your subclass has no default constructor. What are you trying to accomplish with subclassing ‘Test’?


(nangonda patil) #5

would like to add some check operations before and after actual test execution. This is true for all test tasks so want to have custom task which is subclass of Test.


(nangonda patil) #6

Thanks Peter !!

was able to proceed by supplying parametrized constructor


(Bastien MARY) #7

@Nangonda patil, can you please provide your solution here? i have exactly the same problem


(nangonda patil) #8

public class MyTestType2 extends Test {

MyTestType2(org.gradle.listener.ListenerManager listenerManager,

org.gradle.logging.StyledTextOutputFactory textOutputFactory,

org.gradle.api.internal.file.FileResolver fileResolver,

org.gradle.internal.Factory<org.gradle.process.internal.WorkerProcessBuilder> processBuilderFactory,

org.gradle.messaging.actor.ActorFactory actorFactory,

org.gradle.internal.reflect.Instantiator instantiator,

org.gradle.logging.ProgressLoggerFactory progressLoggerFactory){

super(listenerManager,textOutputFactory,fileResolver,processBuilderFactory,actorFactory,instantiator,progressLoggerFactory); }

}