Naive question why I can't run my task in plugin?


(Zbyszek Sokolowski) #1

Task code:

package com.*.ta.sonarutils.tasks.java
  import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
  /**
 * Created by IntelliJ IDEA.
 * Date: 17.12.12
 * Time: 13:47
 */
class APMSonarPluginFacade extends DefaultTask {
   @TaskAction
  def void run() {
    project.sonar {
      database {
        url = project.database.url
      }
      branch = { project.sonarutils.branch }
      server.url = { project.sonarutils.serverUrl }
    }
    debug
    project.sonar.project {
      name = project.sonarutils.name
    }
  //
super.analyze()
    }

in plugin code:

project.task("APMSonarAnalysis", type: APMSonarPluginFacade, group: 'Sonar', description:
'Run SonarAnalysis preconfigured for APM NG' )

I get error:

15:58:18.374 [main] INFO
o.g.a.i.t.e.SkipTaskWithNoActionsExecuter - Skipping task ':APMSonarAnalyze' as it has no actions.

Moreover how to properly create a task which runs another task but customized like SonarAnalize? gradle 1.3


(René Groeschke) #2

What is the purpose of your APMSonarPluginFacade task? It looks like you try to configure the sonartask plugin here?

When I run your code above the build failes with the following error:

Could not find method sonar() for arguments

With the sonar plugin applied you snippet causes the following error:

Could not find property 'database'

Maybe a better approach to customize the build-in Sonar plugin is to configure different instances of the SonarAnalyze in your plugin.

cheers, René


(Zbyszek Sokolowski) #3

Thank you Rene for answer, partially yes I’m trying to prepare a plugin which will be on one hand facade for sonar plugin and hide complexity of it’s configuration, and from the other hand run different other tools like jstestdriver from within, I need to serve 4 languages java, javascript, c#, cpp, project contains many subprojects some of them contain 2 from 4 aforementioned languages. Moreover copy a few files, change other (configs). For javascript I will use standalone sonar-runner because I couldn’t make sonar - plugin work properly with code coverage data for javascript. I have one more

idea why it fails maybe proper set of working directory would help or maybe not. In the end it works smoothly with sonar-runner. One goal of my custom plugin is prepare DSL with one main closure containing sections for all languages.

“Maybe a better approach to customize the build-in Sonar plugin is to configure different instances of the SonarAnalyze in your plugin.” - could you write more about it? how to achieve it programatically? normally I would use task name1(type: SonarAnalyze), task name2(type: SonarAnalyze) and so on… am I right?