groovy - Issues in passing extra properties to a gradle task -
i having trouble in passing properties gradle task. here build file
buildscript { repositories { } ext { dir = '' } apply plugin: 'java' apply plugin: 'maven' apply plugin: 'groovy' group = 'group' version = 'version' sourcecompatibility = 1.8 targetcompatibility = 1.8 task wrapper(type: wrapper) { gradleversion = '3.4' } repositories { } dependencies { compile gradleapi() compile localgroovy() } as can see, have property dir initialized ''. now, here task
class mytask extends defaulttask { file mydir = project.dir @taskaction public void action() { } } my plugin
class myplugin implements plugin<project> { @override def void apply(project project) { project.tasks.create("mytask", mytask) } } and unit test
public class testplugin { @test public void testplugin() { project project = projectbuilder.builder().build(); project.getplugins().apply(testplugin.class); assert.asserttrue(project.getproject().gettasks().findbyname("mytask") instanceof mytask); } } now when run test, shows error couldn't find dir property.
caused by: groovy.lang.missingpropertyexception am missing something?
your build.gradle script , test not linked in way. in test, create clean new project , first (and only) thing apply custom plugin, creates custom task. task property mydir going set, called property dir not exist in project, exception thrown.
you can either define property dir test project ...
project project = projectbuilder.builder().build(); project.ext.dir = '' project.getplugins().apply(testplugin.class); assert.asserttrue(project.getproject().gettasks().findbyname("mytask") instanceof mytask); ... or apply new plugin project of build.gradle script (when done).
Comments
Post a Comment