【问题标题】:Error while adding SVN revision in JAR manifest with Maven and maven-bundle-plugin使用 Maven 和 maven-bundle-plugin 在 JAR 清单中添加 SVN 修订时出错
【发布时间】:2012-09-18 05:20:29
【问题描述】:

我正在尝试在我的项目清单中添加 SVN 修订号。为此,我使用了 Maven 内部版本号插件,并在我的 Super POM 中添加了以下几行:

<!-- Gets the SVN revision number -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <providerImplementations>
                    <svn>javasvn</svn>
                </providerImplementations>
            </configuration>
        </plugin>
        <!-- Add the SVN revision number in the manifest (works on Hudson only) -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Build>${buildNumber}</Implementation-Build>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

注意配置:

<doCheck>false</doCheck>
<doUpdate>false</doUpdate>

我是故意这样做的,因为如果我有本地修改,“doCheck”会阻止我编译(我想在提交工作之前编译和测试)。

“doUpdate”对我来说也是一个问题,因为我不一定想从存储库更新代码。与上述相同的原因,我想在提交之前进行本地测试(并可能解决冲突)。

我的问题是,在清单中,出现的是:

Implementation-Build: ${buildNumber}

因此变量不会被解释。我错过了什么?

谢谢

编辑: 问题实际上出在 maven-bundle-plugin 上。我在我的项目中使用它来生成 OSGi 包。

项目的 POM 打包如下:

<packaging>bundle</packaging>

代替:

<packaging>jar</packaging>

我猜这会影响 Maven 生命周期。 当我删除 maven-bundle-plugin 时,一切正常。但我无法删除它,因为我的应用程序是 OSGi 应用程序。

【问题讨论】:

  • 很抱歉,您的代码示例对我来说非常适用。但我还没有把它放在 Super Pom 中。直接进入正在创建罐子的 pom。插件是放在&lt;pluginManagement/&gt;还是直接放在&lt;build/&gt;下面?
  • 直接在下可能是因为它在super pom中...但是我不想编辑所有继承自这个super的项目的所有POM POM...

标签: java svn maven buildnumber-maven-plugin maven-bundle-plugin


【解决方案1】:

不要使用配置/存档尝试使用配置/说明来添加您的 ${buildNumber},如下所示:

<plugin>
   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <extensions>true</extensions>
   <configuration>
      <instructions>
         <Implementation-Build>${buildNumber}</Implementation-Build>
      </instructions>
   </configuration>
</plugin>

使用您的方法和 Maven 2,一切都奏效了。我们切换到 Maven 3,maven-bundle-plugin 不满意(与您的行为相同)。这种方法成功了。

【讨论】:

    【解决方案2】:

    问题是混合使用 maven-bundle-plugin 和 maven-jar-plugin 来操作 Jar MANIFEST。

    解决办法:

    在超级 POM 中:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>2.3.7</version>
                    <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Implementation-Build>${buildNumber}</Implementation-Build>
                        </instructions>
                </configuration>
                </plugin>
                ...
            </plugins>
        </pluginManagement>
        <plugins>
            <!-- Gets the SVN revision number -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                    <phase>validate</phase>
                    <goals>
                    <goal>create</goal>
                    </goals>
                </execution>
                </executions>
                <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <providerImplementations>
                    <svn>javasvn</svn>
                </providerImplementations>
                </configuration>
            -</plugin>
        </plugins>
    </build>
    

    就是这样!

    【讨论】:

      【解决方案3】:

      您可以使用Maven Plugin Management

      &lt;pluginManagement/&gt; 下的超级 pom 中添加您的插件定义,如下所示:

      <project>
          ...
          <build>
              <pluginManagement>
                  <plugins>
                      <plugin>
                          <groupId>org.codehaus.mojo</groupId>
                          <artifactId>buildnumber-maven-plugin</artifactId>
                          <version>1.1</version>
                          <executions>
                              <execution>
                                  <phase>validate</phase>
                                  <goals>
                                      <goal>create</goal>
                                  </goals>
                              </execution>
                          </executions>
                          <configuration>
                              <doCheck>false</doCheck>
                              <doUpdate>false</doUpdate>
                              <providerImplementations>
                                  <svn>javasvn</svn>
                              </providerImplementations>
                          </configuration>
                      </plugin>
                      <!-- Add the SVN revision number in the manifest (works on Hudson only) -->
                      <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-jar-plugin</artifactId>
                          <version>2.1</version>
                          <configuration>
                              <archive>
                                  <manifest>
                                      <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                  </manifest>
                                  <manifestEntries>
                                      <Implementation-Build>${buildNumber}</Implementation-Build>
                                  </manifestEntries>
                              </archive>
                          </configuration>
                      </plugin>
                  </plugins>
              </pluginManagement>
          </build>
          ...
      </project>
      

      然后在您想要使用这些现在已配置的插件的项目中,将其添加到 poms:

      <project>
          ...
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>buildnumber-maven-plugin</artifactId>
                  </plugin>
                  <plugin>
                      <artifactId>maven-jar-plugin</artifactId>
                  </plugin>
              </plugins>
          </build>
          ...
      </project>
      

      这应该会为你解决。

      【讨论】:

      • 我试过了......我仍然在清单中得到“Implementation-Build: ${buildNumber}”未解释的标签......
      • @Ben 使用来自this usage page&lt;finalName/&gt; 示例进行测试。尝试查看您的 jar 文件是否会在名称中包含内部版本号。
      • 我试过了:在我的模块(不是超级 POM)的 POM 中添加了“buildnumber-maven-plugin-1.1-r${buildNumber}”。它在目标目录中创建了以下 JAR:buildnumber-maven-plugin-1.1-r${buildNumber}.jar
      • 好的,很难说为什么它不起作用。尝试设置除buildNumber 之外的另一个属性名称。也许有些名字冲突。在配置中使用此标记:&lt;buildNumberPropertyName&gt;myOwnBuildNumberName&lt;/buildNumberPropertyName&gt; 并改用该属性。
      • 我也试过了... 在 Super POM 中:&lt;configuration&gt; &lt;doCheck&gt;false&lt;/doCheck&gt; &lt;doUpdate&gt;false&lt;/doUpdate&gt; &lt;providerImplementations&gt; &lt;svn&gt;javasvn&lt;/svn&gt; &lt;/providerImplementations&gt; &lt;buildNumberPropertyName&gt;myOwnBuildNumberName&lt;/buildNumberPropertyName&gt; &lt;/configuration&gt; 仍然在 Super POM 中,在 Manifest 部分:&lt;Implementation-Build&gt;${myOwnBuildNumberName}-${pom.artifactId}&lt;/Implementation-Build&gt;
      猜你喜欢
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2017-08-25
      • 1970-01-01
      相关资源
      最近更新 更多