Problem with conventional mapping


(igor.bljahhin) #1

Hello,

I am developing custom plugin with custom task, which has a number of parameters. The parameters of custom task must have default values and the user of the plugin can override the values. I found in the documentation that conventional mapping should be used in this case.

Here is the part of custom task with fields:

class RebelGenerateTask extends DefaultTask {

def boolean showGenerated

@TaskAction

def generate() {

project.logger.info "rebel.showGenerated = " + isShowGenerated()

} }

Here is part of custom plugin, where RebelGenerateTask task is defined:

class RebelPlugin implements Plugin {

def void apply(Project project) {

project.extensions.rebel = new RebelPluginExtension()

RebelGenerateTask generateRebelTask = project.tasks.add(‘generateRebel’, RebelGenerateTask)

generateRebelTask.conventionMapping.showGenerated = { project.rebel.showGenerated }

} }

As you can see, I defined extension and here it is:

class RebelPluginExtension {

boolean showGenerated }

In my test project, I try to configure RebelPlugin plugin in this way:

apply plugin: ‘java’ apply plugin: ‘rebel’

buildscript {

repositories { mavenLocal() }

dependencies { classpath group: ‘org.zeroturnaround’, name: ‘gradle-jr-plugin’, version: ‘1.0-SNAPSHOT’ } }

rebel { showGenerated = true }

Unfortunately, the field RebelGenerateTask.showGenerated is always “false”. What I do wrong?

gradle version is

c:\projects\gradle-jr-plugin-demoApp>gradle --version

------------------------------------------------------------ Gradle 1.0-milestone-6 ------------------------------------------------------------

Gradle build time: neljapфev, 17. November 2011 5:54:12 UTC Groovy: 1.8.4 Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 Ivy: 2.2.0 JVM: 1.6.0_27 (Sun Microsystems Inc. 20.2-b06) OS: Windows 7 6.1 amd64

Thank you in advance!


(Peter Niederwieser) #2

Could you please fix the syntax highlighting?


(igor.bljahhin) #3

I can’t find any “edit” button on this topic.


(igor.bljahhin) #4

If I change the type of “showGenerated” to String, then the value is passed from build script to custom task. Why?


(Peter Niederwieser) #5

Convention mapping doesn’t work for primitive types. You have to use ‘Boolean’ instead of ‘boolean’.