How to run a plugin twice in one project?


(Vadim Yagodin) #1

Hello guys,

I am new to gradle and groovy. I’m in process of migration from maven to gradle. I have a problem with compiling less css for my project. I have two types of less css: core and country specific.

So in my build file under web project I am using gradle-lesscss-plugin and it has task - lesscss. I would like to run it twice with different direcotries.

When you have one type of less css it is simple, just implement it like this:

apply plugin: 'lesscss'
  lesscss {
    source = fileTree('src/main/less') {
        include 'style.less'
    }
    dest = 'src/main/webapp/assets/css'
}

But I would like to use it twice like this:

apply plugin: 'lesscss'
  task processCoreLess() {
lesscss {
    source = fileTree('src/core/less') {
        include 'style.less'
    }
    dest = 'src/main/webapp/assets/core/css'
}
  }
task processCountryLess() {
lesscss {
    source = fileTree('src/country/less') {
        include 'style.less'
    }
    dest = 'src/main/webapp/assets/country/css'
}
}

How can I do this in gradle? Thanks.


(Luke Daley) #2

You just simply create a new task of the same type:

task processCoreLess(type: de.obqo.gradle.lesscss.LessTask) {
  …
}

Check out this chapter of the user guide: http://www.gradle.org/docs/current/userguide/more_about_tasks.html


(Vadim Yagodin) #3

I’ve did it in this way:

task compileCoreLess (Type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCore}/common/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/core/page.css"
    }
      task compileCountryLess (Type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCountry}/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/country/page.css"
    }

And it says me this:

Deprecated dynamic property: "source" on "task ':web-vivus-es:compileCoreLess'", value: "directory 'D:\Users\wo...".
Deprecated dynamic property: "dest" on "task ':web-vivus-es:compileCoreLess'", value: "D:\Users\workspace\loa...".
Deprecated dynamic property "source" created in multiple locations.
Deprecated dynamic property "dest" created in multiple locations.
:web:compileCoreLess UP-TO-DATE
:web:compileCountryLess UP-TO-DATE
:web:combineCss

It does nothing. Less files are not compiled.


(Luke Daley) #4

You have ‘Type: de.obqo.gradle.lesscss.LessTask’ where it should be ‘type: de.obqo.gradle.lesscss.LessTask’.


(René Groeschke) #5

there is a typo in your task declaration. use “type:” instead of “Type:”

cheers, René


(Vadim Yagodin) #6

When I use ‘type’ it says:

Deprecated dynamic property: "source" on "task ':web-vivus-es:compileCoreLess'", value: "directory 'D:\Users\wo...".
Deprecated dynamic property: "dest" on "task ':web-vivus-es:compileCoreLess'", value: "D:\Users\workspace\loa...".
Deprecated dynamic property "source" created in multiple locations.
Deprecated dynamic property "dest" created in multiple locations.
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not determine the dependencies of task ':web:compileCoreLess'.

But I have classpath dependency in my buildscript block:

classpath ‘de.obqo.gradle:gradle-lesscss-plugin:1.0-1.3.3’

And it works fine if I run the plugin using lesscss task.


(Luke Daley) #7

Please provide your task definitions. They aren’t being declared correctly.


(Vadim Yagodin) #8
task compileCoreLess (type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCore}/common/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/core/page.css"
    }
      task compileCountryLess (type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCountry}/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/country/page.css"
    }

(Luke Daley) #9

This works for me. Can you provide a self contained complete script that exhibits the problem for you?


(Vadim Yagodin) #10

I have cut my build script to minimum but it still complies on dependencies:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.eriwen:gradle-css-plugin:1.1.2'
        classpath 'de.obqo.gradle:gradle-lesscss-plugin:1.0-1.3.3'
    }
}
  allprojects {
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'maven'
  }
   project('web') {
      apply plugin: 'css'
    apply plugin: 'lesscss'
      description = 'Web'
       ext.webCore = "${projectDir}/../../modules/web/src/main/webapp/"
 ext.webCountry = "${projectDir}/../../modules-country/web/src/main/webapp/"
    task compileCoreLess (type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCore}/common/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/core/page.css"
    }
      task compileCountryLess (type: de.obqo.gradle.lesscss.LessTask) {
        source = fileTree("${webCountry}/css/") {
            include 'page.less'
        }
        dest = "${buildDir}/less/country/page.css"
    }
      combineCss {
        dependsOn compileCoreLess, compileCountryLess
      source = fileTree(dir: "${buildDir}/less/", includes: ["**/*.css"])
        dest = "${buildDir}/css/all.css"
    }
}

Hope that will help you to help me :slight_smile:


(Luke Daley) #11

That version of the plugin is written in such a way where this is impossible. You should ask the author to release a new version that does not have this problem.


(Vadim Yagodin) #12

ok, I get it. Thank you. Is there a possibility to use maven plugins?


(Stig Kleppe-Jørgensen) #13

No, you cannot use Maven plugins in Gradle, but you can use ant tasks.