You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by carioca <sh...@gmail.com> on 2008/03/11 14:38:55 UTC

Please help - Injecting a custom plugin parameter

Hi,

I have a problem which seems to be easy to resolve but I have difficulties
with it.

I am developing a custom plugin that contains a Mojo that doesn't requires a
project.
The Mojo is invoked from an empty working directory.
What the Mojo does is get a parameter defined in the plugin's POM and print
it to the log.
The problem is that I don't know how to pass this parameter to the Mojo.

Here is an example:

In the Mojo class I define the member param to be injected with the value of
a parameter called myParam.

/**
 * @parameter expression="${myParam}"
 */
private String param;

When the Mojo executes it suppose to print the parameter's value

public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Param value is: " + param);
}

In the plugin's POM I define the parameter

<project...>
    ...
    <properties>
        <myParam>Hello World!</myParam>
    </properties>
    ...
</project>

The plugin is installed in the local repository.

When I invoke the Mojo I get the following message:

[0] Inside the definition for plugin 'maven-myplugin-plugin' specify the
following:

<configuration>
  ...
  <myParam>VALUE</myParam>
</configuration>

-OR-

on the command line, specify: '-DmyParam=VALUE'


I tried to include my plugin in the plugins section in the POM of the plugin
itself (some kind of crazy recursive inclusion) as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-myplugin-plugin</artifactId>
    <configuration>
        <myParam>Hello World!</myParam>
    </configuration>
</plugin>

but I still get the same message.

If I invoke the plugin from a working directory that contains a pom.xml file
the defines this parameter the Mojo executes successfully.

Does anyone know how to define a parameter in a custom plugin and use the
value of this parameter in the Mojos of the plugin?

Shai
-- 
View this message in context: http://www.nabble.com/Please-help---Injecting-a-custom-plugin-parameter-tp15976512s177p15976512.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Please help - Injecting a custom plugin parameter

Posted by carioca <sh...@gmail.com>.
Hi Brian,

Thank you for replying.
I tried to do what you said, but still with no success.
That's ok cause in the mean time I found a better solution to my challenge.

However I have an improvement suggestion to the maven team to make an easy
way to define properties in the plugin's pom that can be used by the
plugin's Mojos.

In addition, the AbstractMojo class contains the method getPluginContext()
that returns an empty map. I still don't know how to pass values via this
context.

Does anyone know?

Regards,
Shai



The plugin properties are injected at runtime from the project they run
on. The properties defined in the plugin's pom are used to build the
plugin not run it. You could do this, just in a different way. Make a
property file in  your plugin project and filter the value into it. Then
when  your plugin runs you can read this property.

-- 
View this message in context: http://www.nabble.com/Please-help---Injecting-a-custom-plugin-parameter-tp15976512s177p16004053.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Please help - Injecting a custom plugin parameter

Posted by "Brian E. Fox" <br...@reply.infinity.nu>.
The plugin properties are injected at runtime from the project they run
on. The properties defined in the plugin's pom are used to build the
plugin not run it. You could do this, just in a different way. Make a
property file in  your plugin project and filter the value into it. Then
when  your plugin runs you can read this property.


-----Original Message-----
From: carioca [mailto:shaiw75@gmail.com] 
Sent: Tuesday, March 11, 2008 9:39 AM
To: users@maven.apache.org
Subject: Please help - Injecting a custom plugin parameter


Hi,

I have a problem which seems to be easy to resolve but I have
difficulties
with it.

I am developing a custom plugin that contains a Mojo that doesn't
requires a
project.
The Mojo is invoked from an empty working directory.
What the Mojo does is get a parameter defined in the plugin's POM and
print
it to the log.
The problem is that I don't know how to pass this parameter to the Mojo.

Here is an example:

In the Mojo class I define the member param to be injected with the
value of
a parameter called myParam.

/**
 * @parameter expression="${myParam}"
 */
private String param;

When the Mojo executes it suppose to print the parameter's value

public void execute() throws MojoExecutionException,
MojoFailureException {
    getLog().info("Param value is: " + param);
}

In the plugin's POM I define the parameter

<project...>
    ...
    <properties>
        <myParam>Hello World!</myParam>
    </properties>
    ...
</project>

The plugin is installed in the local repository.

When I invoke the Mojo I get the following message:

[0] Inside the definition for plugin 'maven-myplugin-plugin' specify the
following:

<configuration>
  ...
  <myParam>VALUE</myParam>
</configuration>

-OR-

on the command line, specify: '-DmyParam=VALUE'


I tried to include my plugin in the plugins section in the POM of the
plugin
itself (some kind of crazy recursive inclusion) as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-myplugin-plugin</artifactId>
    <configuration>
        <myParam>Hello World!</myParam>
    </configuration>
</plugin>

but I still get the same message.

If I invoke the plugin from a working directory that contains a pom.xml
file
the defines this parameter the Mojo executes successfully.

Does anyone know how to define a parameter in a custom plugin and use
the
value of this parameter in the Mojos of the plugin?

Shai
-- 
View this message in context:
http://www.nabble.com/Please-help---Injecting-a-custom-plugin-parameter-
tp15976512s177p15976512.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org