You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dietrich Schulten <sc...@escalon.de> on 2005/11/17 08:06:27 UTC

[M2] Using variable expressions

Hi,

Every now and then I see references to variables in the format
${some.expression}. However, I do not fully understand them: which
variables are there?

1. User variables

You can define your own variables and use them in the pom like this:
<property>
     <name>variable1</name>
     <value>somevalue</value>
</property>
now I can refer to it:
  ...${variable1}
Or I can pass -Dvariable1=somevalue and refer to it in the same manner.

2. POM element variables

Another use case are values defined in other pom elements:
${artifactId} refers to project/artifactId.
However, I do not understand how to refer to nested elements. Would I
have to use ${parent.artifactId} to get the artifact of the parent?

3. Plugin parameters

If I get the documentation pages for plugins right, the parameter column
is the name of the parameter to be used in <configuration/> elements,
whereas the expression column is the property to pass using -D. For
instance, eclipse:add-maven-repo does it that way: To pass the eclipse
workspace, you can use:
<configuration>
  ...
  <workspace>VALUE</workspace>
</configuration>
-OR-
on the command line, specify: '-Declipse.workspace=VALUE'

4. Built-in variables?

Are there any built-in variables, such as the current project path, I
can refer to? Are they specified somewhere?

Regards,
Dietrich


Re: [M2] Using variable expressions

Posted by dan tran <da...@gmail.com>.
See inline

On 11/16/05, Dietrich Schulten <sc...@escalon.de> wrote:
>
> Hi,
>
> Every now and then I see references to variables in the format
> ${some.expression}. However, I do not fully understand them: which
> variables are there?
>
> 1. User variables
>
> You can define your own variables and use them in the pom like this:
> <property>
> <name>variable1</name>
> <value>somevalue</value>
> </property>
> now I can refer to it:
> ...${variable1}
> Or I can pass -Dvariable1=somevalue and refer to it in the same manner.

 In addition, the main usage is for property reuse. Onc can define a set of
properties
at the parent pom, and have all the children pom to use them. but I beleive
the
synctax is
  <properties>
 <name>value</name>
 ....
 </properties>

2. POM element variables
>
> Another use case are values defined in other pom elements:
> ${artifactId} refers to project/artifactId.
> However, I do not understand how to refer to nested elements. Would I
> have to use ${parent.artifactId} to get the artifact of the parent?

 In a POM, you can use any system property (ie ${java.home} ) + user
properties.
${basedir} is the special case you can refer to the pom's directory.
 Not sure if you can use ${artifactID}, let me know if it works this way
too. if it does
${project.artifactId} is the syntax

3. Plugin parameters
>
> If I get the documentation pages for plugins right, the parameter column
> is the name of the parameter to be used in <configuration/> elements,
> whereas the expression column is the property to pass using -D. For
> instance, eclipse:add-maven-repo does it that way: To pass the eclipse
> workspace, you can use:
> <configuration>
> ...
> <workspace>VALUE</workspace>
> </configuration>
> -OR-
> on the command line, specify: '-Declipse.workspace=VALUE'

 Any time you can see "(Optional)" in the plugin param description,
you can override the default value by either enter the value to your
pom.build's
configuration, or passsing it from command line like you have said.

4. Built-in variables?
>
> Are there any built-in variables, such as the current project path, I
> can refer to? Are they specified somewhere?

 see 2
However, ${basedir} is automatically prefixed any plugin param of type File
so I hardly use this expression.

Regards,
> Dietrich
>
> Hope it helps

  -D

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