Change properties in pom.xml at runtime with Maven Ant Tasks. Is it Possible?

前端 未结 2 1558
渐次进展
渐次进展 2020-12-20 01:00

I have the following use case: My application is started with an Ant Script, which asks the user several questions about the project configuration (database settings etc.).

相关标签:
2条回答
  • 2020-12-20 01:42

    You can redefine the properties on the maven command line using -D and these will override the properties in your project file.

    For example, in pom.xml

      <properties>
         <myProp>A</myProp>
      </properties>
    

    In your ant build.xml, you can then invoke the mvn command line like

    mvn -DmyProp=B install
    

    which Will set myProp to B in the project. The mvn ant task page discusses using a macro to invoke the maven commandline. This can be easily customized to also pass the additional properties.

    To do this in maven alone, use the exec plugin to launch maven, passing the command parameters in the same way as done using the ant:java task.

    0 讨论(0)
  • 2020-12-20 01:44

    Did you try to replace the properties on the fly through <copy> ant task ?

    Assume your properties are in file settings.properties. Define the properties to replace in your pom.xml with @ around them, you can copy the pom file and substitute some properties at the same time. E.g.:

    <copy file='pom.xml' toFile='real-pom.xml'>
      <filterset filtersfile='settings.properties' />
    </copy>
    

    Then you invoke maven:

    mvn -f real-pom.xml

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