Maven 2 从存储库而不是相对文件路径获取maven模块

Maven 2 从存储库而不是相对文件路径获取maven模块,maven-2,Maven 2,我的父项目是: <modules> <module>../module1</module> <module>../module2</module> <module>../module3</module> </modules> ../module1 ../module2 ../module3 和具有 <parent> <groupId>com

我的父项目是:

<modules>
    <module>../module1</module>
    <module>../module2</module>
    <module>../module3</module>
</modules>

../module1
../module2
../module3
和具有

<parent>
    <groupId>com.cc</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

com.cc
父母亲
0.0.1-快照

我是否可以指定,如果../module2/处没有src,则从存储库加载这些模块时会失败,原因是:java.io.FileNotFoundException:C:\work\temp\wid7\workspace\module2(系统找不到指定的文件)。?

可以通过配置文件解决问题

<profiles>
    <profile>
        <id>module1</id>
        <activation>
            <file>
                <exists>../module1/pom.xml</exists>
            </file>
        </activation>
        <modules>
            <module>../module1</module>
        </modules>
    </profile>

    <profile>
        <id>module2</id>
        <activation>
            <file>
                <exists>../module2/pom.xml</exists>
            </file>
        </activation>
        <modules>
            <module>../module2</module>
        </modules>
    </profile>
    ...
</profiles>

模块1
../module1/pom.xml
../module1
模2
../module2/pom.xml
../module2
...
配置文件将模块块连接到一个模块。所以其他模块都是从存储库中获取的。

虽然ArchCC已经为您的问题提供了解决方案,但这里的主要问题是您误解了模块的概念

模块是构建时关系,而不是运行时依赖关系(尽管它们通常没有意义,除非它们也被引用为依赖关系)。多模块项目允许您使用公共配置在一个步骤中执行复杂的构建。一旦构建完成,部署的pom中的
块就没有任何意义,因此如果没有模块,那么指定模块是毫无意义的

如果您的问题是只想构建项目的一部分,那么解决方案是使用高级reactor命令。下面是mvn--help的一段摘录:

usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make                        If project list is specified, also
                                        build projects required by the
                                        list
 -amd,--also-make-dependents            If project list is specified, also
                                        build projects that depend on
                                        projects on the list
 -pl,--projects <arg>                   Build specified reactor projects
                                        instead of all projects
 -rf,--resume-from <arg>                Resume reactor from specified
构建模块api和客户端/impl(嵌套模块也在此处工作)及其所有依赖项(在当前树中)

构建模块核心和将其作为依赖项引用的所有模块

mvn -rf my/deep/nested/module
从指定模块恢复反应堆构建(场景:由于第25个模块中的单元测试,您有一个巨大的构建失败。因此,您修复了测试并从您所在的位置继续,节省了重新构建所有以前模块的时间)



编辑:我刚刚意识到您的模块在根目录之外。在我看来,这违反了maven模块的概念,因为它破坏了上面指定的反应堆功能。

模块的平面结构不会破坏反应堆功能,平面项目布局部分。但是发布插件不支持它。我理解模块的思想,但当您有50个模块时,只需要更改其中的一小部分,没有逻辑来重建所有模块,也没有逻辑来从存储库中检出模块。反应堆的扩展选项有助于解决一半的问题,但似乎我试图找到过于理想的解决方案=(这里的存储库使用情况如何?
mvn -amd -pl core
mvn -rf my/deep/nested/module