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