Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set properties referenced from dependencies in Maven

In my project I've got maven dependency.
by the way it's:

<dependency>
   <groupId>org.mule.modules</groupId>
   <artifactId>mule-module-activiti</artifactId>
   <version>3.2.0</version>
</dependency>

In this dependency POM there is a property that is used but not defined - ${activiti.version}

The only way I found how to set this property is by specifying it on the command line like mvn -Dactiviti.version=5.10

Is there some way how to specify this property in my project's POM?
<properties><activiti.version>5.10</activiti.version></properties> doesn't work.

EDIT:

Situation I'm trying to solve can be reproduced if you create new maven project with dependency:

<dependency>
   <groupId>org.mule.modules</groupId>
   <artifactId>mule-module-activiti</artifactId>
   <version>3.2.0</version>
</dependency>

and provide required repositories:

  <repositories>
        <repository>
            <id>muleforge-repo</id>
            <name>MuleForge Repository</name>
            <url>http://repository.muleforge.org/release</url>
            <layout>default</layout>
        </repository>

        <repository>
            <id>codehaus-repo</id>
            <name>Codehaus Repository</name>
            <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>activiti</id>
            <name>Activiti</name>
            <url>https://maven.alfresco.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>

EDIT 2:

Here is a POM for org.mule.modules:mule-module-activiti:3.2.0, library my projects depends on. Inside of this pom they use expression ${activiti.version}. But they don't set value for this expression. (there is nothing like <properties><activiti.version>5.10</activiti.version></properties>)

The question is how can I set a value for this expression from my pom?

like image 901
Ondrej Bozek Avatar asked Aug 29 '12 09:08

Ondrej Bozek


People also ask

Where are Maven properties set?

Maven Settings Properties. You can also reference any properties in the Maven Local Settings file which is usually stored in ~/. m2/settings. xml.

What is properties tag in Maven?

Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java.

Where do you put dependencies in POM xml?

Open the pom. xml file. under the project tag add <dependencies> as another tag, and google for the Maven dependencies.


2 Answers

OK, finally, after a few days of searching and experimenting I found a solution for my problem.

If you need to provide properties for maven on the command line (talking about system properties, which are slightly different from maven properties), you can also use a plugin to provide these properties in your pom or in the separate properties file.

note: System properties can be used for overriding maven properties in your dependencies.

Like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <configuration>
                <properties>
                    <property>
                        <name>activiti.version</name>
                        <value>5.10</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

I hope it will be of some help to someone.

Also sorry for my clumsy question which was apparently hard to understand.

like image 163
Ondrej Bozek Avatar answered Oct 11 '22 12:10

Ondrej Bozek


You can use properties to define versions:

<properties>
  <module-version>3.2.0</module-version>
</properties>
..
<dependency>
   <groupId>org.mule.modules</groupId>
   <artifactId>mule-module-activiti</artifactId>
   <version>${module-version}</version>
</dependency>

Why shouldn't that work?

You should never define versions of artifacts via properties on command line, cause you can't reproduce this in the future and i doubt that this works.

like image 39
khmarbaise Avatar answered Oct 11 '22 14:10

khmarbaise