Maven - Reading a property from an external properties file

前端 未结 2 1621
逝去的感伤
逝去的感伤 2020-12-06 04:39

I have a property file with the following

junit.version=3.8.1
dbcp.version=5.5.27
oracle.jdbc.version=10.2.0.2.0

I try to read those proper

相关标签:
2条回答
  • 2020-12-06 05:26

    u can define like this:

    <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-2</version>
                <executions>
                    <execution>
                    <id>pre-clean-config</id>
                        <phase>pre-clean</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>config.properties</file>
                            </files>
                        </configuration>
                    </execution>
                    <execution>
                    <id>initialize-config</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>config.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    0 讨论(0)
  • 2020-12-06 05:33

    The initialize phase is not part of the clean lifecycle. You need to also bind your properties plugin to pre-clean phase.

    However, the dependency resolution runs before resolving and executing other plugins, so your approach won't work.

    The proper way to deal with that would be to move dependency versions into a parent pom.xml and use the same parent pom in both of your projects.

    0 讨论(0)
提交回复
热议问题