Using gradle plugin inside a sub project

I am using this plugin: gradle-grunt-plugin

My build file consists of different sub-project(s) having different tasks defined in them. In one of the sub project (which is a web app and uses Grunt to compile code), I would like to use grunt via this plugin within gradle. I would like to know what would be best way to use this plugin inside that sub project?

Following is my test code:

  project('webApp') {
	  task compileWebApp(type: GruntTask, dependsOn: 'copyPackage') {
	    //Compile web app
	    doLast {
	      grunt_build
	      grunt_compile.dependsOn('grunt_build')
	      println 'In compileWebApp task.'
	    }
	  }
	}

When I compile this code it throws error: > Task with path ‘nodeSetup’ not found in project ‘:smile:webApp’.

Can anyone let me know what would be best way to use the plugin inside a subproject? Thanks.

You can apply the plugin via…

  1. load plugin jar at top of build.gradle.
  2. apply the plugin in project(':webApp'){} block.

So, the build script will become like as follows.

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }

  dependencies {
    classpath 'com.moowork.gradle:gradle-grunt-plugin:0.11'
  }
}

project(':webApp') {
    apply plugin: 'com.moowork.grunt'
    grunt_compile.dependsOn grunt_build
    task compileWebApp(type: GruntTask, dependsOn: ['grunt_compile', 'copyPackage']) {
        println 'In compileWebApp task.'
    }
}
1 Like