Maven variable for reactor root

后端 未结 7 1698
攒了一身酷
攒了一身酷 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

    Use directory-maven-plugin with directory-of goal.

    Unlike other suggestions:

    • This solution works for multi-module projects.
    • It works whether you build the whole project or a sub-module
    • It works whether you run maven from the root folder or a sub-module (unlike ${session.executionRootDirectory}
    • There's no need to set a relative path property in each and every sub-module!

    The plugin lets you set a property of your choice to the absolute-path of any of the project's modules. In my case I set it to the root module... In my project root pom:

     
        org.commonjava.maven.plugins
        directory-maven-plugin
        0.1
        
            
                directories
                
                    directory-of
                
                initialize
                
                    myproject.basedir
                    
                        com.my.domain
                        my-root-artifact
                    
                
            
        
    
    

    From then on, ${myproject.basedir} in any sub-module pom always has the path of the project root module. And of course, you can set the property to any module, not just the root...

提交回复
热议问题