1

Summary

When using maven-install-plugin:install-file to install maven jar package all dependencies are ignored and this plugin write a dumb/broken pom file.

Context

I have a local Maven package jar file foo-java-1.2.3.jar which contains its own pom.xml in META-INF/maven/org.mizux.foo/foo-java/pom.xml with few dependencies

<dependencies>
  <dependency>
    <groupId>org.mizux.foo</groupId>
    <artifactId>foo-linux-x86-64</artifactId>
    <version>1.2.3</version>
    <type>jar</type>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna-platform</artifactId>
    <version>5.5.0</version>
  </dependency>
  <dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>3.12.2</version>
  </dependency>
</dependencies>

Then, I tried to install it locally using:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=foo-java.1.2.3.jar
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=foo-linux-x86-64.1.2.3.jar

ref: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

note: net.java.dev.jna:jna-platform and com.google.protobuf:protobuf-java can be found on maven central...

Then when using it in a Bar project pom.xml:

...
<dependencies>
  <dependency>
    <groupId>org.mizux.foo</groupId>
    <artifactId>foo-java</artifactId>
    <version>1.2.3</version>
    <type>jar</type>
    <scope>compile</scope>
  </dependency>
</dependencies>

while mvn compile pass ?

I can't run my Bar's main since all transitive dependencies of foo-java are not passed to Bar so I got some java.lang.NoClassDefFoundError

mvn exec:java -Dexec.mainClass="org.mizux.bar.Test"
...
java.lang.NoClassDefFoundError: com/sun/jna/Platform

Looking at ~/.m2/repository/org/mizux/foo/foo-java/1.2.3/foo-java-1.2.3.pom this one seems to only contains the minimum (groupID, artifactID...) but the whole dependencies part is not present !!

questions:

  • How I can install local maven jar package so the pom installed is the full one and not a truncated version.
  • Why install plugin generate this dummy pom while the complete one is present inside the jar artifact ?

note: When using mvn install on a local build of foo-java the pom exported in .m2 is vastly different i.e. it's a copy of the foo-java original pom.xml ! i.e.

%diff ~/.m2/repository/org/mizux/foo/foo-java/1.2.3/foo-java-1.2.3.pom .../foo-java/pom.xml

note2: here a github project to reproduce the issue https://github.com/Mizux/java-ortools you can take a look at action to see a full log https://github.com/Mizux/java-ortools/actions on linux/macos/windows and a docker ubuntu container

Mizux
  • 8,222
  • 7
  • 32
  • 48

2 Answers2

0

Since the feature you are expecting does not work:

Either use the latest version of the plugin (3.0.0-M1) to see if this is fixed

Either run maven in debug (mvnDebug -X) and place a break point in the line below; for all that matters, your JAR file is probably broken.

Either extract the pom manually and pass it.

NoDataFound
  • 11,381
  • 33
  • 59
  • no all this information are extracted to the jar itself see https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html third cmd, the problem is the maven-install-plugin only extract those and discard all other contents, What I want is the plugin to ALSO copy the pom.xml verbatim – Mizux Jul 07 '20 at 09:56
  • Well, if that does not work, you've don't have much choice: you have to analyse why this fail. – NoDataFound Jul 08 '20 at 10:31
0

Why install plugin generate this dummy pom while the complete one is present inside the jar artifact ?

According to the doc

Generate a minimal POM for the artifact if none is supplied via the parameter pomFile. Defaults to true if there is no existing POM in the local repository yet.

ref: https://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#generatePom

Now I don't know if we can force the maven-install-plugin to copy the pom.xml present in the jar file itself (ed which is already parsed by the plugin !!!)

Ugly workaround

I could extract the pom.xml from the .jar file (which contains it!) then pass it along the jar in the install-file command.

unzip -j foo-java-1.2.3.jar META-INF/maven/org.mizux.foo/foo-java/pom.xml

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \
-Dfile=foo-java-1.2.3.jar -DpomFile=pom.xml

mvn compile

mvn exec:java -Dexec.mainClass="org.mizux.bar.Bar"
Mizux
  • 8,222
  • 7
  • 32
  • 48