1

I have a local jar (a maven plugin I wrote myself) which I am installing with

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=dependencies/my-maven-plugin-1.0.jar

The plugin has some dependencies (defined in the pom.xml within the jar);

<dependencies>
<dependency>
  <groupId>org.apache.maven</groupId>
  <artifactId>maven-plugin-api</artifactId>
  <version>2.0</version>
</dependency>
<dependency>
  <groupId>org.apache.maven.plugin-tools</groupId>
  <artifactId>maven-plugin-annotations</artifactId>
  <version>3.2</version>
  <scope>provided</scope>
</dependency>
  <dependency>
    <groupId>org.yaml</groupId>
    <artifactId>snakeyaml</artifactId>
    <version>1.13</version>
  </dependency>
  <dependency>
    <groupId>com.hubspot.jinjava</groupId>
    <artifactId>jinjava</artifactId>
    <version>2.1.0</version>
  </dependency>
  <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
  </dependency>
</dependencies>

But using the maven-install-plugin, these are not installed. Can I somehow install the needed dependencies automatically when installing the jar?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Nathan
  • 7,099
  • 14
  • 61
  • 125

2 Answers2

1

No, you can't do that. And it is normal: the maven-install-plugin will install the file you pass it, which in this case is my-maven-plugin-1.0.jar, and that's it. It will also look inside the JAR to find a POM to install as well, because without a POM installed, the installed artifact won't be usable as a dependency.

But it doesn't do it, because it isn't needed. Next time you depend on this artifact, with the coordinates written in the POM, Maven will automatically download the dependencies from your configured remote repositories (Maven Central by default) and install them in the local repository. There won't be the need to manually launch the install-file goal; this is only useful when the artifact isn't available on Maven repositories.

If the maven-install-plugin would also install the dependencies of the artifact to manually install, it would just do the same thing Maven itself would do when you finally depend on that artifact in one of your projects.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Thanks for the answer! Maven does not seem to install the dependencies when I am trying to use the plugin. I updated my answer to show my usage. Am i doing something wrong? – Nathan Oct 10 '16 at 13:15
  • @Nathan This looks like the artifact `snakeyaml` is corrupted in your local repo. Remove the folder `~/.m2/repository/org/yaml/snakeyaml` and try again. Be sure to correctly set a proxy in you're behind one. Maven will redownload it, you can check that folder again after to see if what was downloaded isn't corrupted again (the POM and JAR should be the same as [those files](http://repo1.maven.org/maven2/org/yaml/snakeyaml/1.13/)). – Tunaki Oct 10 '16 at 13:26
  • The directory exists and looks fine to me (I also I tried deleting the repo). When I install the plugin using "mvn install" form the plugins source directory everything is fine. – Nathan Oct 10 '16 at 13:43
  • @Nathan Try to make a [mcve] of that issue. This would be a different question that the one asked here though, which was about the `install-file` goal and it not installing the dependencies. I'd suggest posting that into a new question once you have a simple reproducible example (sample plugin code, plugin POM and usage), because I can't reproduce that. – Tunaki Oct 10 '16 at 13:48
  • Ok, I did here: http://stackoverflow.com/questions/39960571/install-custom-maven-plugin-from-local-jar-into-local-repository-with-dependenci Thanks for the help! – Nathan Oct 10 '16 at 14:26
  • @Nathan Thanks. Since you asked a new proper question (and solved :) ), I put this question back in its first revision. I hope this one also helps you understanding this plugin and Maven better! – Tunaki Oct 10 '16 at 19:17
0

I've encountered a similar issue, and the solution here didn't quite work for me. I'm documenting my findings and solution for the benefit of others.

When installing maven-built jars into a new repository with the maven-install-plugin:2.5.2:install-file target, maven is reading the pom.xml embedded within the jar's META-INF directory to install/generate the pom.xml into the repository.

However, maven is not installing the pom.xml from the jar, but instead is generating an empty pom.xml using the artifact Id, group Id and version Id from the jar.

This means that the installed jar has no dependencies which caused my builds to fail.

This is documented as a bug in the install-file project (https://issues.apache.org/jira/browse/MINSTALL-110), which also reports this bug as fixed in v3.0.0-M1 of the project.

So the version of the install-file project to use is maven-install-plugin:3.0.1:install-file as documented here (https://maven.apache.org/plugins/maven-install-plugin/examples/custom-pom-installation.html).

(After writing all of this - I finally found that the real answer had been posted in the comments which i hadn't noticed initially because I didn't agree with the accepted solution - Install custom maven plugin from local jar into local repository with dependencies)

AlexW
  • 311
  • 2
  • 3