You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Marco Hunsicker <de...@hunsicker.de> on 2006/11/07 23:32:21 UTC

Override default-values

Hello all,

Creating a plugin, I would like to use the default compile source
roots for source lookup, but let the user override the default values
at wish. 

I've added the following in my Mojo:

    /**
     * The source directories containing the sources to be formatted.
     *
     * @parameter  property="sources" default-value="${project.compileSourceRoots}"
     */
    private List aSources;

    
which produces the following plugin.xml:

    <mojo>
      <goal>experiment</goal>
      <requiresDirectInvocation>false</requiresDirectInvocation>
      <requiresProject>true</requiresProject>
      <requiresReports>false</requiresReports>
      <aggregator>false</aggregator>
      <requiresOnline>false</requiresOnline>
      <inheritedByDefault>true</inheritedByDefault>
      <implementation>com.systems.plugin.maven.MyMojo</implementation>
      <language>java</language>
      <instantiationStrategy>per-lookup</instantiationStrategy>
      <executionStrategy>once-per-session</executionStrategy>
      <parameters>
        <parameter>
          <name>sources</name>
          <type>java.util.List</type>
          <required>false</required>
          <editable>true</editable>
          <description>The source directories containing the sources to be formatted.</description>
        </parameter>
      </parameters>
      <configuration>
        <sources implementation="java.util.List" default-value="${project.compileSourceRoots}"/>
      </configuration>
    </mojo>


Looks good to me, but when I create a POM and configure the sources
attribute, the specified value is ignored and only the default value
used!

    <plugin>
      <groupId>com.systems.plugin.maven</groupId>
      <artifactId>systems</artifactId>
      <configuration>
        <sources>
          <source>v:/test/demo.java</source>
        </sources>
      </configuration>
      <executions>
        <execution>
          <phase>process-classes</phase>
          <goals>
            <goal>experiment</goal>
          </goals>
        </execution>
      </executions>
    </plugin>


If I remove the default-value="${project.compileSourceRoots}"
attribute from the @parameter tag, the custom value is used, but then
I don't get any default value.

I'm using Maven 2.0.4 on a WinXP box and a Sun 5.0_09 VM. Am I doing
something wrong here or is such a configuration not possible? Any help
would be appreciated! Thank you.


My current workaround is to add another field which provides the
default value and merge the information later on. But according to the
documentation it should be possible to leverage the default-value
attribute and such a solution would be preferred.

Cheers,


Marco Hunsicker


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


Re: Override default-values

Posted by Raphaël Piéroni <ra...@gmail.com>.
Hi Marco,

IIRC the ${project.compileSourceRoots} property contains a list of paths
(maybe even a list of File which are directories)

And it seems you used the source tag to inject a java file instead of a
directory


Hope this helps and is revelant.


Regards,

Raphaël



2006/11/7, Marco Hunsicker <de...@hunsicker.de>:
>
> Hello all,
>
> Creating a plugin, I would like to use the default compile source
> roots for source lookup, but let the user override the default values
> at wish.
>
> I've added the following in my Mojo:
>
>     /**
>      * The source directories containing the sources to be formatted.
>      *
>      * @parameter  property="sources" default-value="${
> project.compileSourceRoots}"
>      */
>     private List aSources;
>
>
> which produces the following plugin.xml:
>
>     <mojo>
>       <goal>experiment</goal>
>       <requiresDirectInvocation>false</requiresDirectInvocation>
>       <requiresProject>true</requiresProject>
>       <requiresReports>false</requiresReports>
>       <aggregator>false</aggregator>
>       <requiresOnline>false</requiresOnline>
>       <inheritedByDefault>true</inheritedByDefault>
>       <implementation>com.systems.plugin.maven.MyMojo</implementation>
>       <language>java</language>
>       <instantiationStrategy>per-lookup</instantiationStrategy>
>       <executionStrategy>once-per-session</executionStrategy>
>       <parameters>
>         <parameter>
>           <name>sources</name>
>           <type>java.util.List</type>
>           <required>false</required>
>           <editable>true</editable>
>           <description>The source directories containing the sources to be
> formatted.</description>
>         </parameter>
>       </parameters>
>       <configuration>
>         <sources implementation="java.util.List" default-value="${
> project.compileSourceRoots}"/>
>       </configuration>
>     </mojo>
>
>
> Looks good to me, but when I create a POM and configure the sources
> attribute, the specified value is ignored and only the default value
> used!
>
>     <plugin>
>       <groupId>com.systems.plugin.maven</groupId>
>       <artifactId>systems</artifactId>
>       <configuration>
>         <sources>
>           <source>v:/test/demo.java</source>
>         </sources>
>       </configuration>
>       <executions>
>         <execution>
>           <phase>process-classes</phase>
>           <goals>
>             <goal>experiment</goal>
>           </goals>
>         </execution>
>       </executions>
>     </plugin>
>
>
> If I remove the default-value="${project.compileSourceRoots}"
> attribute from the @parameter tag, the custom value is used, but then
> I don't get any default value.
>
> I'm using Maven 2.0.4 on a WinXP box and a Sun 5.0_09 VM. Am I doing
> something wrong here or is such a configuration not possible? Any help
> would be appreciated! Thank you.
>
>
> My current workaround is to add another field which provides the
> default value and merge the information later on. But according to the
> documentation it should be possible to leverage the default-value
> attribute and such a solution would be preferred.
>
> Cheers,
>
>
> Marco Hunsicker
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>