Maven variable for reactor root

后端 未结 7 1706
攒了一身酷
攒了一身酷 2020-12-07 22:41

In a multi-module maven project, is there a variable that points to the root project folder?

  • ${project.basedir} points to the current project\'s d
7条回答
  •  情话喂你
    2020-12-07 23:11

    For me, there was a need for root directory during variable interpolation, not for plugins section - for local directory relative to root with hand-crafted jars. I know this is a bad practice to have local directory with jars, but this was a requirement of project.

    Why I was unable to use different solutions:

    • ${session.executionRootDirectory} and ${user.dir} are tied with directory from which maven command was executed. I want to refer to the same directory independently of directory, from which maven was launched.
    • ${project.basedir} ,as mentioned above, points to current project directory, so child modules will search for jars in wrong location.
    • I had about 100 projects, so defining relative paths or usage of accepted answer for this question is quite complex in my case.
    • Directory plugin can be used only for plugin configurations, not for variable interpolation

    So, in my case with bad requirements I have used environment variable which refers project root and used it in pom.xml. Use it as last resort, when other solutions do not work. Here is example, how I use environment variable in my case:

    
        
            local-maven-repo
            
            file:///${env.PROJECT_ROOT}/local-repo
        
    
    

提交回复
热议问题