我有几个模块运行"mvn clean install
",并且必须保持它们的顺序。为了让我的生活更轻松,不必改变TFS
或任何东西,我想创建项目聚合器,它将拥有我所有的sub-modules
,而他们对这个aggregator
一无所知。 我的项目结构:
projectaggregator
|
+- submodule1
|
+- submodule2
聚合器/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: srcmainresourcesyamldecision.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
子模块1/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
无法找到资源,因为我们正在通过aggregator
运行submodule1
。 有没有办法在不修改 pom 文件的情况下解析对资源的relative path
submodule1
?
在使用 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