smallrye / jandex

Java Annotation Indexer
Apache License 2.0
398 stars 94 forks source link

Migrating from Jandex maven plugin 1.1.1 to 3.1.3 fails to create intermediate directories when generating an index #327

Closed rlubke closed 1 year ago

rlubke commented 1 year ago

Consider the following jandex plugin configuration:

          <execution>
            <id>make-index-country</id>
            <goals>
              <goal>jandex</goal>
            </goals>
            <!-- phase is 'process-classes by default' -->
            <phase>pre-integration-test</phase>
            <configuration>
              <indexName>country-index/custom.idx</indexName>
              <fileSets>
                <fileSet>
                  <directory>${testClassesDirectory}/data/portabletype</directory>
                  <includes>
                    <include>Country.class</include>
                  </includes>
                </fileSet>
              </fileSets>
            </configuration>
          </execution>

This fails with the following:

Caused by: java.nio.file.NoSuchFileException: /Users/rlubke/files/coh/dev/release/coherence-v14.1.1.2206/prj/test/functional/io/target/classes/META-INF/address-index/custom.idx
    at sun.nio.fs.UnixException.translateToIOException (UnixException.java:92)
    at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:111)
    at sun.nio.fs.UnixException.rethrowAsIOException (UnixException.java:116)
    at sun.nio.fs.UnixFileSystemProvider.newFileChannel (UnixFileSystemProvider.java:182)
    at java.nio.channels.FileChannel.open (FileChannel.java:292)
    at java.nio.channels.FileChannel.open (FileChannel.java:345)
    at org.codehaus.plexus.util.io.CachingOutputStream.<init> (CachingOutputStream.java:57)
    at org.codehaus.plexus.util.io.CachingOutputStream.<init> (CachingOutputStream.java:51)
    at org.codehaus.plexus.util.io.CachingOutputStream.<init> (CachingOutputStream.java:46)
    at org.jboss.jandex.maven.JandexGoal.execute (JandexGoal.java:176)

Workaround: use the antrun plugin to create the target directories prior to generating the indexes.

Ladicek commented 1 year ago

In previous Jandex Maven plugin versions (before 3.0), each fileset got its own index, whose name (and, coincidentally, also path, though I don't think that was ever intended) was always META-INF/<indexName>.

Since 3.0, all filesets contribute to a single index, whose location is configured using <indexDir> and <indexName> (see https://smallrye.io/jandex/jandex/3.1.3/maven/advanced.html#_index_location_and_version).

If you need to create multiple indices, you need to use multiple executions of the Jandex Maven plugin.

Specifically the example above can be fixed by splitting <indexName>country-index/custom.idx</indexName> into <indexDir>${project.build.outputDirectory}/META-INF/country-index</indexDir> <indexName>custom.idx</indexName>.

Ladicek commented 1 year ago

On the other hand, maybe we should support <indexName> containing a path, if that worked before (even if perhaps unintentionally). I'll fix that, should be easy.