我使用Swagger (OpenAPI)来设计和实现一个API。我已经有了一个功能性swagger.yml和一个Maven项目,用于基于它构建文档、服务器和客户端。
swagger-codegen-maven-plugin在/target/generated-sources/swagger目录中生成抽象类和实现类。我应该用自己的实现类覆盖实现类,所以我将实现类的初始版本移到/src/main/java目录中。
在移动类之后,我的构建正确地完成了,但是如果我做了一个mvn clean compile,我就会在我的构建中出现重复类的错误。
每次我做一个干净的构建时,swagger-codegen-maven-plugin都会重新生成所有的代码,包括我正在重写的类。
swagger-codegen-maven-plugin创建了一个.swagger-codegen-ignore,在这里我应该列出我不希望它生成的文件,但它似乎不起作用(我使用的是插件的2.2.2版快照)。
#.swagger-codegen-ignore
OrcamentoApiServiceImpl.java
PropostaApiServiceImpl.java作为解决办法,我试图使maven-compiler-plugin排除生成的文件版本,以便只使用我修改过的实现进行编译,但它也不起作用。下面是我使用的配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>OrcamentoApiServiceImpl.java</exclude>
<exclude>PropostaApiServiceImpl.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>我如何让maven-compiler-plugin忽略由swagger插件生成的文件的版本,而只考虑我的呢?
或者:你能提出另一种解决方案吗?或者如何使swagger-codegen-maven-plugin考虑到.swagger-codegen-ignore?
发布于 2016-12-23 19:54:22
我遇到了完全相同的问题,我设法使傲慢的忽略文件工作。根据我从他们的文档中所了解到的(用一个恰当的例子可以更清楚地理解),忽略文件必须设置在生成的代码的根处。因此,我在我的pom.xml中添加了这个插件,以便从它的实际位置复制它:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/generated-sources/swagger</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>.swagger-codegen-ignore</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>https://stackoverflow.com/questions/41269182
复制相似问题