Maven jandex plugin does not generate index for local custom maven repositories (sometimes)

677 views Asked by At

I have a multi module maven project wie quarkus modules and some custom libraries which are local maven repositories (so they can be used by the other maven projects/modules). However, so that local maven repositories are recognizable und usable by your other local maven projects, you have to manually index them for some reason. I.e. add a config like this for quarkus index to the application.properties of the project including the local maven repo dependency:

quarkus.index-dependency.<index-name>.group-id = <group-id-of-local-maven-repo>
quarkus.index-dependency.<index-name>.artifact-id = <artifact-id-of-local-maven-repo>

The problem is, this causes issues for me becausse if you have 3 layers of project dependencies, say:

  1. Project A (custom local maven repo library)
  2. Project B (custom local maven repo library, includes Project A dependency)
    • application.properties (indexing Project A library dependency)
  3. Project C (Local maven project for an end product, includes Project B library dependency - and through it indirectly Project A).
    • application.properties (indexing Project B library dependency and config for datasources or other app related things)

Then when you generate an uber-jar (fat jar) of Project C for deployment, it for some reason uses application.properties of Project B in the packaged jar, instead of from the project which im building (Project C). Thus, the app is missing key configs and does not work. Maven seems to use an inverse priority here, which i dont know if thats a bug or not. When i asked about this, i was simply told that:

"My dependencies should not have application.properties".

I tried to find a way to prevent manual indexing via application.properties and found the maven jandex plugin - which is supposed to generate an index. The next problem is, this seems to only work in some projects but not in others in the dependency hierarchy, resulting in the same situation as before, and i don't understand why. This is the pom.xml config for the plugin i have included in all 3 projects (the entire pom.xml for all is too long, so let me know if you need more info):

<properties>
    ...
    <jandex.skip>false</jandex.skip>
    ...
</properties>
...
<build>
    ...
    <plugin>
        <groupId>io.smallrye</groupId>
        <artifactId>jandex-maven-plugin</artifactId>  
        <version>3.0.5</version>     
        <inherited>true</inherited> 
        <executions>
           <execution>  
              <id>make-index</id>
              <goals>
                 <goal>jandex</goal>
              </goals>
           </execution>
        </executions>
        <configuration>
            <skip>${jandex.skip}</skip>
        </configuration>
    </plugin>
    ...

The odd thing is, this works to the extend that i no longer have to index Project B library dependency in Project C application.properties, but Project B library dependency still has to manually index Project A library dependency - thus rendering the entire exercise futile. Project C having an application.properties was never the issue, and is obviously needed. Project B still requires a properties file to point to Project A now, how do i solve this?


I have a parent module POM in the root folder containing all these projects, over which this maven jandex dependency is distributed to all modules, so it looks like this:

  • Maven parent module (contains all dependencies and versions used by all project sub modules)

    1. Project A (custom local maven library repo), own pom.xml with inheritance from parent module
    2. Project B (custom local maven library repo, includes Project A library), own pom.xml with inheritance from parent module
      • application.properties - Indexes Project A dependency manually, this is the problematic one which needs to go!
    3. Project C (Local maven project for REST API etc., includes Project B library), own pom.xml with inheritance from parent module

    pom.xml (parent module POM, containing maven jandex dependepency among others)


Edit: One of the projects, "entity", where all the database access objects are stored, does not run the jandex plugin during mvn clean install. This is the POM of the project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.compamny.project</groupId>
   <artifactId>entity</artifactId>
   <version>1.0-SNAPSHOT</version>
   <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       <maven.compiler.source>17</maven.compiler.source>
       <maven.compiler.target>17</maven.compiler.target>
   </properties>
   <dependencies>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-hibernate-orm</artifactId>
        <version>2.16.1.Final</version>
      </dependency>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-hibernate-validator</artifactId>
        <version>2.16.1.Final</version>
      </dependency>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
        <version>2.16.1.Final</version>
      </dependency>
      <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jdk8</artifactId>
        <version>2.13.3</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.smallrye/jandex-maven-plugin -->
      <dependency>
        <groupId>io.smallrye</groupId>
        <artifactId>jandex-maven-plugin</artifactId>
        <version>3.0.0</version>
      </dependency>
    </dependencies>
   <build>
     <pluginManagement>
       <plugins>
         <plugin>
           <artifactId>maven-clean-plugin</artifactId>
           <version>3.1.0</version>
         </plugin>
         <plugin>
           <artifactId>maven-resources-plugin</artifactId>
           <version>3.0.2</version>
         </plugin>
       <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
       </plugin>
       <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
       </plugin>
       <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
       </plugin>
       <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
       </plugin>
       <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
       </plugin>
       <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
       </plugin>
       <plugin>
         <artifactId>maven-project-info-reports-plugin</artifactId>
         <version>3.0.0</version>
       </plugin>
       <plugin>
         <groupId>io.smallrye</groupId>
         <artifactId>jandex-maven-plugin</artifactId>
         <version>3.0.0</version>        
         <inherited>true</inherited>
         <executions>
           <execution>            
             <id>make-index</id>
             <goals>
                <goal>jandex</goal>
             </goals>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </pluginManagement>
 </build>
</project>

When i force the execution of the jandex goal with mvn io.smallrye:jandex-maven-plugin:3.0.0:jandex it creates an META-INF/jandex.jdx file, but it does not produce one when i run mvn clean install. This is not a solution since i need to build the project, run the jandex plugin and install it into my local repositories separately. Also, notice that im using the "io.smallrye" version of the jandex plugin since the "org.jboss" version seems to not work at all.

1

There are 1 answers

2
Furious Gamer On BEST ANSWER

I figured it out. The jandex plugin was set in the <pluginManagement> section of the POM configuration, which made it not run on mvn clean install. I had to move it to the plugins section so it gets executed. Thanks @Ladicek for making me look closer and keep trying!