repackaging 2 libraries, with proper module configuration

22 views Asked by At

I am facing the issue described here : Java module issues with Confluent Kafka libraries (split package)

in a nutshell : there's a "split package" situation with 2 Kafka / Avro jars, with classes in same java package, but in 2 different jars in 2 different modules (JPMS).

I want to try to repackage and "merge" the 2 jars, following what is described here : java 9 module reads package X from A and B

but it's not working, so I guess I am missing something.

I created a new Maven module in my project, and simply put this in the pom.xml :

<artifactId>avro-serializer-repackaged</artifactId>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>          
    </plugins>
</build>


<dependencies>
    <dependency>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-avro-serializer</artifactId>
        <version>7.5.1</version>
        <exclusions>
            <exclusion>
                <groupId>io.confluent</groupId>
                <artifactId>kafka-schema-serializer</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-schema-serializer</artifactId>
        <version>7.5.1</version>
    </dependency>
</dependencies>

the build "works", and generates a jar. However, when I look into the jar and open the module-info.class, here's what I have, which I am not really able to explain :

module com.fasterxml.jackson.annotation {
    exports com.fasterxml.jackson.annotation;

    opens com.fasterxml.jackson.annotation;
}

So of course, when I try to use the jar in the other Maven module, declaring that I wan to use the avro.serializer.repackaged module, it doesn't work.

I tried adding this :

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Automatic-Module-Name>avro.serializer.repackaged</Automatic-Module-Name>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

But that didn't change anything.

I also tried to add a module-info.java under src/main/java , but since I have no code and just a pom.xml, I am not sure what to put there..

So I am stuck now, and I don't see how I can migrate y project to use JPMS. Is there a chance to make this work, and build a jar with a proper module descriptor ?

Also, I am super puzzled that something as popular as Kafka / Avro faces this.. isn't anyone using these 2 jars in a project using java modules ?

0

There are 0 answers