当由聚合器pom调用时,Maven无法读取子模块的资源

时间:2018-10-19 13:04:52

标签: maven

我有几个运行“ mvn clean install”的模块,必须维护它们的顺序。为了使我的生活更轻松并且不必更改TFS或其他任何内容,我考虑过创建一个project aggregator来容纳我所有的sub-modules,而他们对此aggregator一无所知。 我的项目结构:

projectaggregator
|
+- submodule1
|
+- submodule2

aggregator / pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my.package</groupId>
    <artifactId>projectaggregator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Project Aggregator</name>

    <modules>
        <module>../submodule1</module>
        <!--<module>../submodule2</module>-->       
    </modules>
</project>

并且构建失败并出现以下错误:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] submodule1
[INFO] Project Aggregator
[INFO] 
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 8
[INFO]                                                                         
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Building Project Aggregator 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Building submodule1 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- swagger-codegen-maven-plugin:2.3.1:generate (default) @ submodule1 ---
[INFO] reading from src/main/resources/yaml/decision.yaml
[INFO] reading from src/main/resources/yaml/decision.yaml
[ERROR] failed to read resource listing
java.io.FileNotFoundException: src\main\resources\yaml\decision.yaml (The system cannot find the path specified)
    at java.io.FileInputStream.open0(Native Method)
...
[INFO] No .swagger-codegen-ignore file found.
[ERROR] java.lang.RuntimeException: missing swagger input or config! 

...
[INFO] --------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] submodule1 ....................................... FAILURE [  3.983 s]
[INFO] Project Aggregator ............................... SUCCESS [  0.003 s]
[INFO] --------------------------------------------------------------------
[INFO] BUILD FAILURE

submodule1 / pom.xml:

...
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.3.1</version>
        </dependency>
    ...

很显然submodule1找不到资源,因为我们正在运行submodule1aggregator。 是否有任何方法可以将relative path解析为资源而无需修改submodule1 pom文件?

1 个答案:

答案 0 :(得分:1)

当我用招摇过头执行多模块构建时,我遇到了同样的问题。在查看资源路径时,显然使用了swagger插件。 我们可以通过在swagger插件配置中使用maven变量${project.basedir}来解决此问题:

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.2.1</version>
    <executions><execution>
        <goals><goal>generate</goal></goals>
        <phase>generate-sources</phase>
        <configuration>
            <inputSpec>${project.basedir}/src/main/resources/yaml/decision.yaml</inputSpec>
        </configuration>
    </execution></executions>
</plugin>

此处引用-https://github.com/swagger-api/swagger-codegen/issues/3583