0

My problem is that I want to have an external lib imported into the local maven repository of the user automatically.

Here is how I get it working using maven-install-plugin :

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
            <executions>
                <execution>
                    <id>install-external</id>
                    <phase>clean</phase>
                    <configuration>
                        <file>${basedir}/myjar.jar>
                        <repositoryLayout>default</repositoryLayout>
                        <groupId>mygroupid</groupId>
                        <artifactId>myartefactid</artifactId>
                        <version>myversion</version>
                        <packaging>jar</packaging>
                        <generatePom>true</generatePom>
                    </configuration>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

But with this in pom, in order to have it working I have to execute in two different commands :

mvn clean 
mvn install

If I am just runing

 mvn clean install

It's failling not resolving my dependency during the install phase (except if I have done a mvn clean alone and I havn't clean the local repository of course). Clean seems to call the pluging only if I run 'mvn clean' alone.

What I would like is to have my dependency automatically imported when runing 'mvn install'. Or at least while runing 'mvn clean install' in a single command.

bloub
  • 416
  • 3
  • 16
  • Where is the library coming from? Another Maven project? – khmarbaise Mar 17 '20 at 19:55
  • What OS do you use? if it works by running `mvn clean` and `mvn install` separately, and you just want a single command to do both, you can just create an alias for it, like: `alias mvnci='mvn clean; mvn install'` – M Imam Pratama Mar 17 '20 at 19:57
  • The library cames from an other company, it's a maven project but they are delivering the library under a .jar format only. – bloub Mar 17 '20 at 20:24
  • I am using ubuntu. But i can't make an alias like that. If I want this problem to be solve it's because I can't explain to some other people that will exploit the project that they have to do theses both step separately. – bloub Mar 17 '20 at 20:30
  • 1
    If you are working in a corporate environment it's usually the case to have a repository manager. Then you can simply put that jar file into your repository manager and reuse as a usual dependency. Anything else makes it more complex; more error prone etc. – khmarbaise Mar 18 '20 at 07:20

1 Answers1

0

Your solution cannot work with just one Maven command.

If you start Maven with mvn something, the dependencies are resolved first, so anything you install by a plugin during the build won't be found.

The solution, as khmarbaise already said, is to put the artifact into a repository first. The usual solution for that is your company Nexus/Artifactory (if you do serious Maven depevelopment, there should be one).

If this is really not possible, you can use a directory as Maven repository as described here: https://stackoverflow.com/a/28762617/927493

J Fabian Meier
  • 30,532
  • 9
  • 61
  • 119