【问题标题】:Maven pom plugin not executing on buildMaven pom插件未在构建时执行
【发布时间】:2018-07-18 22:29:11
【问题描述】:

我正在练习 Maven,但我碰壁了。我已经在 IntelliJ 上安装了 PlantUml 插件,我正在尝试对其进行设置,以便它始终在编译时从源文件生成新图像。我正在使用this 插件生成图像,并且我已将 pom.xml 文件配置如下:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.github.jeluard</groupId>
        <artifactId>plantuml-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <id>GeneratePlantUml</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/images</outputDirectory>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <sourceFiles>
            <directory>${basedir}/plantuml</directory>
            <includes>
              <include>TestGeneratorDiagram.puml</include>
            </includes>
          </sourceFiles>
          <outputDirectory>${basedir}/images</outputDirectory>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>net.sourceforge.plantuml</groupId>
            <artifactId>plantuml</artifactId>
            <version>8031</version>
          </dependency>
        </dependencies>
      </plugin>
    <plugins>
  </pluginManagement>
<build>

当我使用指定目标的终端命令时,这可以正常工作:

mvn compile com.github.jeluard:plantuml-maven-plugin:generate

但是,如果我只是写它是行不通的:

mvn compile

据我所知,这也应该有效。我尝试在编译时设置阶段,但它没有改变任何东西。我已经搜索了几个小时来寻找解决方案,但我还没有找到。有谁知道我如何通过配置 pom 强制插件在编译时生成新图像?

【问题讨论】:

    标签: java xml maven intellij-idea pom.xml


    【解决方案1】:

    您已将配置放入pluginManagement。你需要把它放到plugins外面pluginManagement)。

    pluginManagement 只是覆盖/指定配置和版本号。

    看看Maven: What is pluginManagement?

    【讨论】:

    • 移到plugings后还是不运行怎么办?
    • @dev4life 如果你在这里问一个关于 SO 的新问题,包括你的 POM 和你遇到的错误,那就太好了。
    • 我可能不得不这样做。我看到了类似的问题,但尝试了解决方案,但仍然对我不起作用。我试图避免发布另一个“我的插件未运行”线程,但我想我也会有。
    【解决方案2】:

    你的插件和你的执行是配置à“生成资源”阶段,而不是像你想要的那样在编译阶段。 有关阶段的更多详细信息,请参阅此link

    改变这个:

    <execution>
            <id>GeneratePlantUml</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
    

    到这里

    <execution>
            <id>GeneratePlantUml</id>
            <phase>compile</phase>
            <goals>
              <goal>generate</goal>
            </goals>
    

    它必须有效。

    【讨论】:

      猜你喜欢
      • 2020-01-21
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多