There appears to be some misunderstanding on your side. Perhaps this is what
you want:
void apply(Project project) {
// this makes the members of DeployPluginConvention available on
'project' (NOT on 'project.deploy')
// the DeployPluginConvention object is internally stored under the key
'deploy',
// which makes it possible to access its members even from tasks/plugins
written in Java
// (e.g. with
'project.getConvention().getPlugins().get("deploy").getApplicationName()')
project.convention.plugins.deploy = new DeployPluginConvention()
// printing out 'applicationName' doesn't make sense here
// because it will only be set further down in the build script
// println "Configuring deploy for $project.applicationName"
def deploy = project.tasks.add("deploy", DeployTask)
// need to set 'earPath' lazily (again because the value for
'applicationName' isn't available yet)
// this is done using Gradle's 'convention mapping' mechanism
deploy.conventionMapping.earPath = { project.applicationName + ".ear" }
}
Disclaimer: I didn't compile or run this code. Usage from build.gradle:
apply plugin: DeployPlugin
applicationName = "foo"
If you want this to be 'deploy.applicationName = "foo"', you'll have to wrap
the DeployPluginConvention object with an object that has a 'deploy'
property, or change installation of the convention object to 'project.deploy
= new DeployPluginConvention()', or use the 'extension' mechanism introduced
in Gradle 1.0-milestone-4. From milestone 4 onwards, the latter is the best
option.
--
Peter Niederwieser
Principal Engineer, Gradleware
http://gradleware.com
Creator, Spock Framework
http://spockframework.org
Twitter: @pniederw
Ricardo Mayerhofer wrote:
>
> The point is I'd like to be able to read convention properties in apply
> method, currently it prints null, which means it wasn't set. Perhaps I'm
> not thinking the gradle way.
>
> I need to configure some tasks in plugin that receive input from
> convention properties, e.g.:
>
> ...
> def void apply(Project project) {
> project.convention.plugins.deploy = new DeployPluginConvention()
>
> println "Configuring deploy for
> ${project.convention.plugins.deploy.applicationName}"
>
> def deploy = project.getTasks().add( "deploy", DeployTask.class )
> deploy.earPath = project.convention.plugins.deploy.applicationName +
> ".ear"
> }
>
> What is the best way to achieve this?
>
--
View this message in context:
http://gradle.1045684.n5.nabble.com/Use-plugin-convention-property-in-apply-method-tp4731829p4737503.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email