Индексирование JAR с использованием maven-bundle-plugin

Я пытаюсь построить пакет, который имеет индекс (META-INF/INDEX.LIST) с помощью maven-bundle-plugin 2.3.7.

Моя конфигурация плагина выглядит следующим образом

  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <archive>
        <index>true</index>
      </archive>
      <instructions>
        <!-- other things like Import-Package -->
        <Include-Resource>{maven-resources}</Include-Resource>
      </instructions>
    </configuration>
  </plugin>

но META-INF/INDEX.LIST не будет отображаться в банке. Я пытался использовать

  <Include-Resource>{maven-resources},META-INF/INDEX.LIST</Include-Resource>

но это не удастся с

[ERROR] Bundle com.acme:project::bundle:1.0.0-SNAPSHOT : Input file does not exist: META-INF/INDEX.LIST
[ERROR] Error(s) found in bundle configuration

что не удивительно, потому что META-INF/INDEX.LIST не в target/classes но динамически генерируется архиватором Maven.

Редактировать 1

Когда я использую jar вместо bundle упаковка, то индекс есть.

Редактировать 2

Я использую Maven 3.0.4

1 ответ

Решение

Копался в исходном коде maven-bundle-plugin, и похоже, что текущая версия (2.3.7) игнорирует index атрибут конфигурации архива. Это также игнорирует compress, forced, а также pomPropertiesFile, Единственные атрибуты конфигурации архива, на которые он обращает внимание, это addMavenDescriptor, manifest, manifestEntries, manifestFile, а также manifestSections,

Я не уверен, есть ли другой способ манипулировать созданным архивом, используя только maven-bundle-plugin.

В качестве возможного обходного пути вы могли бы использовать maven-jar-plugin для повторного jar-пакета после его создания, сообщая плагину jar о создании индекса, но используя манифест, созданный плагином bundle.

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <!-- unpack bundle to target/classes -->
        <!-- (true is the default, but setting it explicitly for clarity) -->
        <unpackBundle>true</unpackBundle>
        <instructions>
            <!-- ... your other instructions ... -->
            <Include-Resource>{maven-resources}</Include-Resource>
        </instructions>
    </configuration>
</plugin>
<!-- List this after maven-bundle-plugin so it gets executed second in the package phase -->
<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <!-- overwrite jar created by bundle plugin -->
                <forceCreation>true</forceCreation>
                <archive>
                    <!-- use the manifest file created by the bundle plugin -->
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    <!-- bundle plugin already generated the maven descriptor -->
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <!-- generate index -->
                    <index>true</index>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

Я не слишком знаком с тем, что требуется в архиве комплектов, поэтому вы можете перепроверить, что все правильно.

Другие вопросы по тегам