开发者

How to react on file in path with property in maven?

开发者 https://www.devze.com 2023-02-11 10:03 出处:网络
I want to use some plugin executions of my maven project only when a certain file does not exist. The path to this file can change - that\'s why it must contain a property (and please correct me if th

I want to use some plugin executions of my maven project only when a certain file does not exist. The path to this file can change - that's why it must contain a property (and please correct me if that's not the case). A good way would be to use profile activation with the file, but because the path has a property this doesn't work (as stated in the Maven 'Introduction to build profiles').

That said, the question is: Do you know a way to achieve the desired behav开发者_开发问答iour only with one pom?

Of course the enforcer plugin offers a limited way of reacting on files but I don't want to necessarily fail or interrupt the build.


There's not really much you can do. Here are your options:

  1. Live with the restrictions. The only way you can configure the file path is through a system property (user properties are evaluated using profiles, not the other way around):

    <profile>
        <id>foobar</id>
        <activation>
            <file><exists>${file.path}</exists></file>
        </activation>
    </profile>
    
    mvn -Dfile.path=some/path/file.txt clean install
    
  2. Invoke the executions programmatically, e.g with the Maven Invoker. Either

    • write a custom plugin or
    • write a main class and call it from Exec:Java or
    • use an inline Groovy Script with GMaven

    Either one of the above options will have to behave as a dispatcher that invokes mojos using the invoker depending on evaluation of properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消