【问题标题】:Skip maven2 plugin by default默认跳过 maven2 插件
【发布时间】:2023-03-05 06:45:01
【问题描述】:

我正在寻找一种在安装时不执行插件的方法。更具体地说,我的场景如下:

  1. 我正在使用 org.apache.cxf:cxf-codegen-plugin 来生成源代码。
  2. 每次我清理+安装源都会生成
  3. 我只希望在我明确请求时生成源代码。

我们将不胜感激任何和所有的帮助!

【问题讨论】:

    标签: maven-2 jax-ws cxf wsdl2java


    【解决方案1】:

    我只希望在我明确请求时生成源代码。

    最好的选择是在配置文件中添加插件声明并显式激活此配置文件:

    <project>
      ...
      <profiles>
        <profile>
          <id>codegen</id>
          ...
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                  <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                      <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                      <wsdlOptions>
                        <wsdlOption>
                          <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
                        </wsdlOption>
                      </wsdlOptions>
                    </configuration>
                    <goals>
                      <goal>wsdl2java</goal>
                    </goals>
                  </execution>
                </executions>
              </plugin>
            </plugins>
          </build>
        </profile>
      </profiles>
    </project>
    

    当您希望代码生成发生时,运行以下命令:

    mvn clean install -Pcodegen
    

    【讨论】:

    • 这正是我要找的!谢谢:-)
    • OP 应该希望代码生成默认启用并根据请求禁用!这对其他开发人员更友好(他们不会因为忘记代码生成而出错),并且以某种方式简化了 CI 设置。
    【解决方案2】:

    我相信你想在你的 POM 中为 cxf 的 plugin 元素添加一个 executions 元素。您应该能够将生成目标绑定到您喜欢的阶段。见:http://maven.apache.org/pom.html#Plugins

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2019-10-05
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多