【问题标题】:Generating changeset and adding it to JAR with Maven使用 Maven 生成变更集并将其添加到 JAR
【发布时间】:2023-02-01 10:54:29
【问题描述】:

我正在使用 maven-changelog-plugin 生成一个 git diff 变更集。这个插件在我运行mvn sitemvn changeset:changeset时运行,并将变更集文件输出到target/site/changeset.html/target/changeset.xml。我想将这个生成的文件包含在我运行mvn clean install 时构建的 jar 中。

如何将这个生成的文件包含在 JAR 中?我试过使用 build-helper-maven-plugin 添加工件或添加源,但似乎变更集是作为最后一步创建的或不可发现的。

我最近的尝试:

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-changelog-plugin</artifactId>
        <version>2.3</version>
        <reportSets>
          <reportSet>
            <id>changelog-report</id>
            <configuration>
              <type>range</type>
              <range>30</range>
            </configuration>
            <reports>
              <report>changelog</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

  <profiles>
    <profile>
      <id>add-changelog-to-artifact</id>
        <activation>
            <file><exists>target/site/changelog.html</exists></file>
        </activation>
        <build>
          <plugins>
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
              <version>3.3.0</version>
              <executions>
                <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals>
                    <goal>add-source</goal>
                  </goals>
                  <configuration>
                    <sources>
                      <source>target/site/changelog.html</source>
                    </sources>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
    </profile>
  </profiles>

【问题讨论】:

  • 查看插件文档,我看不到 changelog:changelog 默认绑定到哪个阶段,但您可以添加插件配置,就像 build-helper-maven-plugin 一样,它将在早期阶段运行更新日志。
  • @tgdavies 我确实尝试向build-helper 插件添加一个阶段,但是在&lt;reporting&gt; block it always runs last. I tried moving the plugin to the &lt;build&gt; block with an earlier phase, and it still did not work. Even using mvn 站点 install, which builds the reports first, does not work because the add-changelog` 插件中使用时找不到该文件

标签: java maven jar dependencies


【解决方案1】:

maven-changelog-plugin 的问题在于它总是在比需要的构建步骤晚的步骤运行。我最终改用了gitlog-maven-plugin,这让我可以改变它执行的阶段

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-13
    • 2012-06-11
    • 2021-09-16
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多