Reputation: 1328
I added the following code to my pom.xml to read properties from an external properties files using the following configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>..\maven.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
In my maven.properties file I have the following:
aspectj-maven-plugin.version=1.4
versions-maven-plugin.version=2.0
I am using ${versions-maven-plugin.version}
in pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions-maven-plugin.version}</version>
<configuration>
<rulesUri>url</rulesUri>
<includesList>com.package:*</includesList>
</configuration>
</plugin>
But an exception is getting thrown when I run mvn clean install
on the package saying the plugin version is invalid. Any reason why this occurs?
Note : Both pom.xml and mave.properties are in the same folder
Upvotes: 1
Views: 3827
Reputation: 328780
The reason is pretty simple: To be able to read the config of the properties-maven-plugin
, Maven has to parse all other plugins as well - it can't know what the plugin does before actually starting it.
While it does that, it notices that it doesn't have all the necessary versions. This validation step happens long before the first plugin is instantiated.
Conclusion: Your approach doesn't work. What you can do is put the properties into the POM and then extract them from there into a properties file (for example using the maven-resources-plugin).
Upvotes: 4