Finding the root directory of a multi module maven reactor project

前端 未结 13 1551
庸人自扰
庸人自扰 2020-12-02 11:11

I want to use the maven-dependency-plugin to copy artifacts from all sub-modules of my multi-module project to a directory that is relative to the root directory of the enti

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 11:30

    use ${session.executionRootDirectory}

    For the record, ${session.executionRootDirectory} works for me in pom files in Maven 3.0.3. That property will be the directory you're running in, so run the parent project and each module can get the path to that root directory.

    I put the plugin configuration that uses this property in the parent pom so that it's inherited. I use it in a profile that I only select when I know that I'm going to run Maven on the parent project. This way, it's less likely that I'll use this variable in an undesired way when I run Maven on a child project (because then the variable would not be the path to the parent).

    For example,

    
        org.apache.maven.plugins
        maven-dependency-plugin
        
            
                copy-artifact
                package
                
                    copy
                
                
                    
                        
                            ${project.groupId}
                            ${project.artifactId}
                            ${project.version}
                            ${project.packaging}
                        
                    
                    ${session.executionRootDirectory}/target/
                
            
        
    
    

提交回复
热议问题