Maven:如何排除带有自定义标志的插件

Maven: How to exclude a plugin with a custom flag

我的 Spring 引导项目 pom.xml 中有一个插件,我希望在 运行 mvn clean install.
时有时禁用该插件 有没有我可以添加到我的 pom.xml 的配置,它会创建一个自定义标志,例如exc,当像这样调用时 mvn clean install -D exc 将构建 jar,而无需该插件。 为清楚起见,这是我想通过 maven 标志禁用的插件:

 <plugin>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-maven-plugin</artifactId>
                <version>${springdoc-openapi-maven.version}</version>
                <configuration>
                    <apiDocsUrl>http://localhost:XXXX/v3/api-docs</apiDocsUrl>
                    <outputDir>${project.basedir}/openapi</outputDir>
                </configuration>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

您可以将 <springdoc.skip>true</springdoc.skip> 添加到您的 <properties> 部分。

然后您可以通过mvn clean install -Dspringdoc.skip=false

激活插件

您可以使用个人资料来做到这一点。添加类似 :

  <profile>
    <id>no-springdoc</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
    <build><plugins>
    <plugin>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-maven-plugin</artifactId>
    <version>${springdoc-openapi-maven.version}</version>
    <configuration><skip>true</skip><configuration>
    </plugin>
    </plugins></build>
  </profile>

然后使用 mvn ... -P no-springdoc 构建应该在没有插件的情况下构建。

https://maven.apache.org/guides/introduction/introduction-to-profiles.html