-1

3rdparty.property

xerces.version=1.0

i have this property file and i want to read it's contents but i was unable to read.

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>3rdparty.properties</file>
                <echo>foo is "${xerces.version}"</echo>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>

log file shows that it has error. the error is

The project com.CAPMOnline:IDLUtils:1608.0.11 (C:\srathaworkspace\IDLUtils\pom.xml) has 1 errors
[ERROR]     'dependencies.dependency.version' for com.3rdParty:xerces:jar must be a valid version but is '${xerces.version}'. @ com.CAPMOnline:IDLUtils:[unknown-version], C:\srathaworkspace\IDLUtils\pom.xml, line 22, column 13
  • Simply write the version into the version tag of the dependency. redirecting to use the version from a property does not has any advantage. – khmarbaise Jul 12 '16 at 10:42

1 Answers1

0

Is the path to your file correct? Try use:

              <files>
                <file>${project.basedir}/3rdparty.properties</file>
              </files>

Also remove the echo statement.

The dependency versions are resolved as soon as the pom is parsed. They cannot be set by a property that is loaded at runtime by a plugin only by a property that already exists. All lifecycle phases get executed after the dependency version has been resolved. The proper approach would be to move your properties to a parent pom and inherit from that.

See here for a related question: Maven - Reading a property from an external properties file

Community
  • 1
  • 1
Revive
  • 2,248
  • 1
  • 16
  • 23
  • no this is not working, as i have tried earlier and the property file is already in correct place i.e basedir. – Sanu Mishra Jul 12 '16 at 10:31
  • means you are saying i cant give the version in a external file and i cant access that if i want to. – Sanu Mishra Jul 12 '16 at 11:05
  • You can pass it through a parent pom. It cannot be loaded through a plugin as all lifecycle phases only execute after the dependency version has been resolved. See edit – Revive Jul 12 '16 at 11:09
  • then what is main use of properties-maven- plugin if it cant read the file to access it. – Sanu Mishra Jul 12 '16 at 11:33
  • is there any other way to access a property file from external source. – Sanu Mishra Jul 12 '16 at 13:43
  • The plugin can populate parameters for plugins in later phases for example.. Yes there is multiple plugins that would allow you to read from a properties file in some manner. Antrun plugin for example but the same limitation will stand. – Revive Jul 12 '16 at 22:14