0

I have looked around from various questions on stackoverflow, but I have not found the answer that solve my purpose.

I want to import a properties file in a pom.xml; my purpose is to replace the <properties> section with the properties loaded from the external file. Each property refers to the version of a particular maven dependency.

I have tried the properties-maven-plugin, but the properties are not solved and the project is not built.

I'm looking for a way that preserve the standard build of Eclipse, and also the mvn install goal of Maven.

As an example, I want that this section:

<properties>
    <dependency1.version>1.0.0</dependency1.version>
</properties>

will be replaced with the property declared in a dependency.properties file, like this one:

dependency1.version=1.0.0

How can I implement my pom.xml in order to obtain this behaviour?

Thanks in advance.

EDIT

This is what I have tried:

<build> 
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>${basedir}/dependencies.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>my version: ${dependency1.version}</echo>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Well, if I do a simple mvn install, in maven console it prints:

[INFO] Executing tasks
     [echo] my version: 1.0.0
[INFO] Executed tasks

So, the plugin solve the property, but when I try to import the dependency with this:

<dependencies>
    <dependency>
        <groupId>dependency1</groupId>
        <artifactId>dependency1</artifactId>
        <version>${dependency1.version}</version>
    </dependency>
</dependencies> 

I obtain this error:

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for dependency1:dependency1:jar must be a valid version but is '${dependency1.version}'. @ line 21, column 13
 @  

The property is solved in the maven-antrun-plugin, but if it is used in the dependencies section, it doesn't work.

Alessandro C
  • 3,310
  • 9
  • 46
  • 82
  • *I have tried the properties-maven-plugin, but the properties are not solved and the project is not built.* Can you show what you tried? [Like this](http://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file-in-maven)? – Tunaki Dec 19 '16 at 10:54
  • I have edited my question, you can see the details! – Alessandro C Dec 19 '16 at 11:01
  • That's a different problem. You can't have the dependency version in a properties. This is not possible by design. – Tunaki Dec 19 '16 at 11:03
  • Oh, I see. Do you know exactly in which part of the documentation of Maven I can read it? I'm interested to understand something more about it. Thank you. – Alessandro C Dec 19 '16 at 11:05
  • 1
    Possible duplicate of [Maven - Reading a property from an external properties file](http://stackoverflow.com/questions/9912632/maven-reading-a-property-from-an-external-properties-file) – Tunaki Dec 19 '16 at 11:07

0 Answers0