Maven variable for reactor root

后端 未结 7 1673
攒了一身酷
攒了一身酷 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 22:44

    In the latest maven, you can use ${maven.multiModuleProjectDirectory}.

    0 讨论(0)
  • 2020-12-07 22:48

    In Maven 3, ${session.executionRootDirectory} is "a variable that always points to the ... directory ... from which the maven command was executed."

    Note that this is distinct from a property that gives the top-level root directory of a multi-module project, regardless of where in the directory structure mvn is executed from. Such a property does not exist to my knowledge, but you can use the ${basedir}/.. hack to achieve it. See this thread on maven-users for more details.

    See also: Finding the root directory of a multi module maven reactor project

    0 讨论(0)
  • 2020-12-07 22:49

    As far I think, there is no such variable. There are only workaround like in accepted answer of Maven2 property that indicates the parent directory .

    0 讨论(0)
  • 2020-12-07 22:59

    Such property can be created using: directory-maven-plugin. Using the plugin's highest-basedir goal you can assign the root path to any property you specify.

    0 讨论(0)
  • 2020-12-07 23:09

    is there a variable that always points to the root directory (the one from which the maven command was executed)

    user.dir (the working directory) should be that directory.

    0 讨论(0)
  • 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:

     <plugin>
        <groupId>org.commonjava.maven.plugins</groupId>
        <artifactId>directory-maven-plugin</artifactId>
        <version>0.1</version>
        <executions>
            <execution>
                <id>directories</id>
                <goals>
                    <goal>directory-of</goal>
                </goals>
                <phase>initialize</phase>
                <configuration>
                    <property>myproject.basedir</property>
                    <project>
                        <groupId>com.my.domain</groupId>
                        <artifactId>my-root-artifact</artifactId>
                    </project>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    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...

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