0

According to Groovy doc, Example 40.2, a new class for a task should be created so (simply copy that to the build.gradle):

task hello(type: GreetingTask)

class GreetingTask extends DefaultTask {
    @TaskAction
    def greet() {
        println 'hello from GreetingTask'
    }
}

But if you really try to do it, the class declaration is marked as an erroneous because no abstract methods are written. About ten of them should be here... Is it really impossible to do a task class in a cheap way as in documentation? What is the problem with documentation? Or rather with some settings on my IntelliJ?

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • Well, if you only need one task of that type, you don't need an own class, but just can do `task hello(type: GreetingTask) { doLast { println 'hello from ad-hoc task' } }`. But your example works fine for me, exactly copy/pasted. – Vampire Jul 25 '17 at 09:59
  • Of course, I am trying to create a class for some real task (I want to make different tasks launches using the same class). But it does not work due to that problem. So, I am putting minimal piece of code that does not work. According to the rules... I am sure that it worked for documentation authors, too. I suspise that the reason is that I have some different settings in IntelliJ. But what to check? – Gangnus Jul 25 '17 at 10:04
  • Does it work from the commandline? Can you show the error? – Vampire Jul 25 '17 at 10:06
  • I have no gradle installed, AFAIK, only Gradle plugin in IntelliJ. At least, I can't run it from command line. And I want it to work in IntelliJ. – Gangnus Jul 25 '17 at 10:08
  • Btw. in my opinion each and every project and be it the smallest test-poc should use the Gradle Wrapper. Then you know that anyone that is not intentionally ignoring it is building your project with the exact same Gradle version you designed your build for and that works for your build and someone who wants to build it needs only a compatible Java version installed, nothing else. – Vampire Jul 25 '17 at 10:12

2 Answers2

1

You are using the wrong DefaultTask class. The one from Gradle is not abstract.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Yes, I have already looked at its code. It only extends AbstractTask. – Gangnus Jul 25 '17 at 10:23
  • Which itself also does not have any abstract methods. Maybe Ctrl+Click and see where IJ thinks it should lead you to. – Vampire Jul 25 '17 at 10:33
  • AbstractTask implements two interfaces. It seems, that Groovy can allow non-abstract classes not to override interface methods. A I have said, it works in both cases - when IntelliJ shows error and when it does not. So, the problem is in IntelliJ showing the error that is not there, It tries to interpret the classes as Java, not Groovy. I'll look at the order of apply.... – Gangnus Jul 25 '17 at 10:41
  • Order of apply plugin java/groovy has no influence. I think it will be something in IntelliJ settings... Thank you fo the help and +1 – Gangnus Jul 25 '17 at 10:44
0

When I create the mentioned task in the empty Gradle/Groovy project, no errors is shown.

In the context of my project, the error IS shown. But the task runs OK! It again seems as some hallucination of IntelliJ.

Gangnus
  • 24,044
  • 16
  • 90
  • 149